Author Posts

September 28, 2015 at 6:11 am


I'm doing a get-wmiobject and selecting objects to export to a csv, however I also want a custom column in there with a variable for each row that has data

So far I have

$user = [Environment]::UserName

Get-WmiObject Win32_MappedLogicalDisk | select name, providername | Export-Csv c:\temp\mapped.csv -Append -notypeinformation

So trying to get a username column in there with each row having $user in

September 28, 2015 at 6:27 am

In general when you want to add a custom column you can just add a hashtable to your Select Statement:

$user = [Environment]::UserName

Get-WmiObject Win32_MappedLogicalDisk | select name, providername,@{Name="Username";Expression={$user}} | Export-Csv c:\temp\mapped.csv -Append -notypeinformation

September 28, 2015 at 6:32 am

I was so close to getting this one, thank you!