How to make a Foreach export-CSV?
hi
i export result of script csv or text file.
how possible?
$dcs = get-content d:\temp\computers.csv foreach($dc in $dcs) { get-adcomputer -identity $dc -properties lastlogontimestamp | select-object @{n="computer";e={$_.name}}, @{name="lastlogon"; expression={[datetime]::fromfiletime($_.lastlogontimestamp)}} }
maelito
hi,
i'd use foreach-object loop instead:
get-content d:\temp\computers.csv | foreach-object { get-adcomputer -identity $_ -properties lastlogontimestamp | select-object @{n="computer";e={$_.name}}, @{name="lastlogon"; expression={[datetime]::fromfiletime($_.lastlogontimestamp)}} } | export-csv .\output.csv -notypeinformation
edit: if actual csv file input you're going have problems this, you're not specifying property use inside of loop though. you'll need add (e.g. $_.yourheader).
Windows Server > Windows PowerShell
Comments
Post a Comment