Automation

 View Only
Expand all | Collapse all

How can I get output only with specific column in CSV

  • 1.  How can I get output only with specific column in CSV

    Posted Jul 15, 2022 06:33 AM

    Hi,

    I have a csv file where multiple columns are present, I would like to get the csv output using VM Name and results only.

    from the below script, I am getting the output appended to existing CSV, But I need VMName and results, please help!

    Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row | 
    ForEach-Object -Process {
    try
    {
    $session = New-SSHSession $row.Name -Credential $Cred -AcceptKey -ErrorAction Stop
    $result = $session | Select-Object -ExpandProperty Connected
    $output = $((Invoke-SSHCommand -SSHSession $session -Command 'uptime -s').output)
    Get-SSHSession | Remove-SSHSession | Out-Null
    }
    catch
    {
    $result = 'False'
    }
    $row | Add-Member -MemberType NoteProperty -Name 'SSH Login' -Value $result -PassThru | Add-Member -MemberType NoteProperty -Name 'Uptime' -Value $output -PassThru
    } | Export-Csv -Path $reportlocation2 -NoTypeInformation -UseCulture



  • 2.  RE: How can I get output only with specific column in CSV
    Best Answer

    Posted Jul 15, 2022 06:46 AM

    You can create a new object with only the properties you want



  • 3.  RE: How can I get output only with specific column in CSV

    Posted Jul 15, 2022 07:34 AM

    Thank you very much...that was perfect