VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Output shows blank without any error

Hi,

I am getting the blank output for below without any error.

Please help.

$reportlocation1 = ".\Servs.csv"
$WPassword =  "Password2"
$code = @'
"### Output ###"
Get-NetAdapterBinding -ComponentID ms_tcpip6 | Select @{N="Computer";E={$($env:COMPUTERNAME)}},@{N="ETH_Name";E={$_.Name}},@{N="ETH_DisplayName";E={$_.DisplayName}},@{N="Status";E={$_.Enabled}} | ConvertTo-Csv -UseCulture -NoTypeInformation
'@

$report = @()
$notFound = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row | where {($_.OS -match "Windows")} |
ForEach-Object -Process {
$found = $false
foreach ($pswd in $WPassword) {
$pass = ConvertTo-SecureString -AsPlainText $pswd -Force
$Creds = New-Object System.Management.Automation.PSCredential ("admin", $pass)
$sInvoke = @{
VM = $row.Name
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
ErrorAction = 'Stop'
}
try {
$result = Invoke-VMScript @sInvoke
$dummy, $out1 = $result.ScriptOutput -split '### Output ###'
$out1 = $out1.TrimStart("`n`r")
$report += $row | ConvertFrom-Csv -UseCulture | Select @{N="Computer";E={$($env:COMPUTERNAME)}},@{N="ETH_Name";E={$_.Name}},@{N="ETH_DisplayName";E={$_.DisplayName}},@{N="Status";E={$_.Enabled}}
$found = $true
break
}
catch {
}
}
if(-not $found){
$notFound += $row
}
}
$report | Format-Table -AutoSize
$notFound | Format-Table -AutoSize

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is no VM property in the object, you can use a calculated property.

Select-Object -Property @{N='VM';E={$row.VM}},Name, DisplayName, Enabled


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Shouldn't that be

$report += $out1 | ConvertFrom-Csv -UseCulture |


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

After making the suggested changes, still the same, but now, it showing me the local computer name and all other fields shows blank

Computer ETH_Name ETH_DisplayName Status
-------- -------- --------------- ------
APP01
APP01
APP01
APP01
APP01
APP01
APP01

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is most probably because the names of the properties don't match.
You are placing for example ETH_Name in the output, but you are retrieving Name, and the same for the other properties.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

Even I provide the direct properties, it is shows blank.

$reportlocation1 = ".\MyVMs.csv"
$reportlocation2 = ".\IPv6_Valid_Info.csv"
$reportlocation3 = ".\IPv6_Invalid_Info.csv"
$WPassword = "Password2"
$code = @'
"### Output ###"
Get-NetAdapterBinding -ComponentID ms_tcpip6 | Select Name, DisplayName, Enabled | ConvertTo-Csv -UseCulture -NoTypeInformation
'@

$report = @()
$notFound = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row | where {($_.OS -match "Windows")} |
ForEach-Object -Process {
$found = $false
foreach ($pswd in $WPassword) {
$pass = ConvertTo-SecureString -AsPlainText $pswd -Force
$Creds = New-Object System.Management.Automation.PSCredential ("admin", $pass)
$sInvoke = @{
VM = $row.VM
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
ErrorAction = 'Stop'
}
try {
$result = Invoke-VMScript @sInvoke
$dummy, $out1 = $result.ScriptOutput -split '### Output ###'
$out1 = $out1.TrimStart("`n`r")
$report += $out1 | ConvertFrom-Csv -UseCulture | Select-Object -Property Name, DisplayName, Enabled
$found = $true
break
}
catch {
}
}
if(-not $found){
$notFound += $row
}
}
$report | Export-Csv -Path $reportlocation2 -NoTypeInformation -UseCulture
$notFound | Export-Csv -Path $reportlocation3 -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since you are only transferring one set of rows, there is no need to use the *** Output *** line.
What does this return?

$reportlocation1 = ".\MyVMs.csv"
$reportlocation2 = ".\IPv6_Valid_Info.csv"
$reportlocation3 = ".\IPv6_Invalid_Info.csv"
$WPassword = "Password2"
$code = @'
Get-NetAdapterBinding -ComponentID ms_tcpip6 | Select Name, DisplayName, Enabled | ConvertTo-Csv -UseCulture -NoTypeInformation
'@

$report = @()
$notFound = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row | where { ($_.OS -match "Windows") } |
    ForEach-Object -Process {
        $found = $false
        foreach ($pswd in $WPassword) {
            $pass = ConvertTo-SecureString -AsPlainText $pswd -Force
            $Creds = New-Object System.Management.Automation.PSCredential ("admin", $pass)
            $sInvoke = @{
                VM              = $row.VM
                GuestCredential = $Creds
                ScriptTYpe      = 'powershell'
                ScriptText      = $code
                ErrorAction     = 'Stop'
            }
            try {
                $result = Invoke-VMScript @sInvoke
                $report += $result.ScriptOutput | ConvertFrom-Csv -UseCulture | Select-Object -Property Name, DisplayName, Enabled
                $found = $true
            } catch {}
        }
        if (-not $found) {
            $notFound += $row
        }
    }
$report | Export-Csv -Path $reportlocation2 -NoTypeInformation -UseCulture
$notFound | Export-Csv -Path $reportlocation3 -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Now I am getting the output but it is not capturing the details for invalid VM and also how can I get the VM Name in the output

I tried as below, it is not working

$report += $result.ScriptOutput | ConvertFrom-Csv -UseCulture | Select-Object -Property VM, Name, DisplayName, Enabled

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is no VM property in the object, you can use a calculated property.

Select-Object -Property @{N='VM';E={$row.VM}},Name, DisplayName, Enabled


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much 🙂

Tags (1)
0 Kudos