Automation

 View Only
  • 1.  Output shows blank without any error

    Posted Sep 30, 2021 04:08 PM

    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



  • 2.  RE: Output shows blank without any error

    Posted Sep 30, 2021 04:42 PM

    Shouldn't that be



  • 3.  RE: Output shows blank without any error

    Posted Sep 30, 2021 05:05 PM

    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



  • 4.  RE: Output shows blank without any error

    Posted Sep 30, 2021 05:22 PM

    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.



  • 5.  RE: Output shows blank without any error

    Posted Oct 01, 2021 04:17 AM

    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



  • 6.  RE: Output shows blank without any error

    Posted Oct 01, 2021 05:18 AM

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



  • 7.  RE: Output shows blank without any error

    Posted Oct 01, 2021 05:49 AM

    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



  • 8.  RE: Output shows blank without any error
    Best Answer

    Posted Oct 01, 2021 06:50 AM

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



  • 9.  RE: Output shows blank without any error

    Posted Oct 04, 2021 05:26 AM

    Thank you very much