Powershell: Export a custom object to a CSV file - extract a single property value with Select-Object

后端 未结 2 629
长情又很酷
长情又很酷 2020-11-30 15:29

I wrote a script that constructs a custom object and exports it to a CSV file:

$reg = Get-ItemProperty HKLM:\\SOFTWARE\\McAfee\\DLP\\Agent | Select-Object ag         


        
2条回答
  •  [愿得一人]
    2020-11-30 16:25

    The expression:

    Select-Object {$_.LastWriteTime}
    

    outputs an object with a single property with name $_.LastWriteTime. The simplest way to fix it is to use the -ExpandProperty parameter which will only output the value that you are interested in. e.g.:

    $date86 = Get-ItemProperty 'C:\Program Files (x86)\McAfee'|
                Select-Object -ExpandProperty LastWriteTime 
    

    Note that I've also removed the script block from the Select-Object command, as it wasn't necessary.

提交回复
热议问题