I'm using the Quest AD cmdlets, particularly Get-QADUser, to pull a list of users from AD and return just a few attributes. No problems, easy enough, but I want to transform one of the properties (parentContainerDN) before exporting to CSV.
Get-QADUser -name "Froosh" | Select-Object logonName,homeDrive,parentContainerDN | Export-CSV C:\Temp\File.csv
This works of course, but the parentContainerDN is long and untidy. Is there an easy way to replace that with parentContainerDN.Name before passing that to Export-CSV?
I'd be happy with a commandline solution, or a script snippet.
Thanks!
The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of objects, or objects in a specified position in an array. To select objects from a collection, use the First, Last, Unique, Skip, and Index parameters.
Most often understood as an acronym for “comma-separated values” (though sometimes called “character-separated values” because the separator character does not have to be a comma), CSV is a file format that stores tabular data in plain-text form.
There's a special syntax to create on-the-fly properties in select-object. Try this (wrapping added for clarity):
get-qaduser -name "hamilmat"
| select-object logonName, homeDrive,
@{Name="containerName"; Expression={$_.parentContainerDN.Name}}
| export-csv ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With