converting a System.Object to a string

dennis weikel 21 Reputation points
2022-07-13T03:24:53.69+00:00

Need help on the following powershell script which I'm trying to implement. I want to extract the Zoom attributes but trim the output so only see the relevant information.

PS H:\> $Zoom_Objects = get-wmiobject -n "root/zoom/vdi" -Class PluginInfo | Select-Object PSComputerName, IsConnectionOptimized, InstalledVersion
PS H:\> Write-output $Zoom_Objects
PSComputerName IsConnectionOptimized InstalledVersion ;Want to Strip this from the output


--------------------- ---------------- ;Want to Strip this from the output
PSCIT-21H2-003 1 5.10.0 (21068) ;This is the only line I'm interested in.


PS H:\> $Zoom_Objects.GetType()
IsPublic IsSerial Name BaseType


True False PSCustomObject System.Object


I want to perform character manipulation so trying to get the following working but receive the following method error. Haven't had any luck converting the system object to a string if that is what is needed.

PS H:\> $Zoom_Objects.substring(5, 20)
Method invocation failed because [Selected.System.Management.ManagementObject] does not contain a method named
'substring'.
At line:1 char:1

  • $Zoom_Objects.substring(5, 20)
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (substring:String) [], RuntimeException
  • FullyQualifiedErrorId : MethodNotFound

Thank in advance for any help or guidance that can be provided.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,620 questions
0 comments No comments
{count} votes

Accepted answer
  1. Aung Zaw Min Thwin 306 Reputation points
    2022-07-13T04:44:23.077+00:00

    If you prefer in csv format:
    $Zoom_Objects | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1

    or you can also use formatted text as below as well:
    "{0} {1} {2}" -f $Zoom_Objects.PSComputerName, $Zoom_Objects.IsConnectionOptimized, $Zoom_Objects.InstalledVersion

    If you still want to manipulate some of the attributes:

    "{0} {1} {2}" -f $Zoom_Objects.PSComputerName.substring(2,5), $Zoom_Objects.IsConnectionOptimized, $Zoom_Objects.InstalledVersion  
      
    

    or, inline string format as below:

    "ComputerName: $($Zoom_Objects.PSComputerName) ConOptimized: $($Zoom_Objects.IsConnectionOptimized) Version: $($Zoom_Objects.InstalledVersion)"

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. dennis weikel 21 Reputation points
    2022-07-13T05:06:59.853+00:00

    Thank you. This was exactly what was needed.

    $Zoom_Objects | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.