Select-Object selecting multiple objects but splitting the results and trimming them export to CSV

前端 未结 1 393
半阙折子戏
半阙折子戏 2021-01-16 00:52

I have a script that reads from a list of computers, does a test connection. If it gets a reply from the Test-Connection, it does a if/else and builds a variabl

相关标签:
1条回答
  • 2021-01-16 01:27

    Expand the IP address:

    ... | Select-Object -Expand IPV4Address | Select-Object -Expand IPAddressToString
    

    and don't turn the directory information into a string:

    $Details = "$LastUserLoggedIn"

    Build your data object like this:

    $obj = [PSCustomObject]@{
      SystemName  = $Computername
      IPV4Address = $ipreachable
      UserName    = $LastUserLoggedIn.Name
      Timestamp   = $LastUserLoggedIn.LastWriteTime
    }
    

    So that you can display the information on the console as well as export it to a CSV:

    $obj | Format-Table -AutoSize
    $obj | Export-Csv 'C:\path\to\your.csv' -NoType -Append
    
    0 讨论(0)
提交回复
热议问题