Hello, good day,
I am trying to run several commands through invoke-vmscript and return an Arraylist within my objects,
Is there a way to achieve this?
$Disks2 = @'
$collectionWithItems = New-Object System.Collections.ArrayList
$netroute1 = Get-NetRoute | Where-Object -FilterScript {$_.NextHop -Ne "::"} | Where-Object -FilterScript { $_.NextHop -Ne "0.0.0.0" } | Where-Object -FilterScript { ($_.NextHop.SubString(0,6) -Ne "fe80::") } | Get-NetAdapter
$networkadapter = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE
$netroute2 = Get-NetRoute | Where-Object -FilterScript { $_.NextHop -Ne "::" } | Where-Object -FilterScript { $_.NextHop -Ne "0.0.0.0" } | Where-Object -FilterScript { ($_.NextHop.SubString(0,6) -Ne "fe80::") }
$dnsclient = Get-DnsClientServerAddress
$netipinterface = Get-NetIPInterface
$temp2 = New-Object System.Object
$temp2 | Add-Member -MemberType NoteProperty -Name netroute1 -Value $netroute1
$temp2 | Add-Member -MemberType NoteProperty -Name networkadapter -Value $networkadapter
$temp2 | Add-Member -MemberType NoteProperty -Name netroute2 -Value $netroute2
$temp2 | Add-Member -MemberType NoteProperty -Name dnsclient -Value $dnsclient
$temp2 | Add-Member -MemberType NoteProperty -Name netipinterface -Value $netipinterface
$collectionWithItems.Add($temp2) | Out-Null
$collectionWithItems | ConvertTo-CSV -NoTypeInformation
'@
$Result2 = Invoke-VMScript -VM $server -GuestUser $GuestUser -GuestPassword $GuestPassword -ScriptText $disks2 -ScriptType Powershell -ErrorAction stop | Select -ExpandProperty ScriptOutput | ConvertFrom-CSV
I have tried with and without Converto-CSV | ConvertFrom-CSV without success.
I would like to work with the objects after the invoke method is run, as example:
$collectionwithitems.netipinterface should return info but $result2.netipinterface is not,
Is there any way to implement this? I have been working a couple days on this :smileysad:
Thanks!