I am new to PowerShell and I am having the following problem.
When typing the following command for asked value of CanonicalNameOfObject
I am receiving Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
. I know that this problem is because that property isn't in a format that is understood by PowerSell in its raw format.
Can somebody help me to put this right? In general I want to have all computers in the company for a specific branch (which is only a separated folder).
Thank you!
Kind regards Kris
Get-ADComputer -Filter * -Property * |
Select-Object Name,CanonicalNameOfObject,OperatingSystem,OperatingSystemVersion,ipv4Address |
Export-CSV c:\ADcomputerslist.csv -NoTypeInformation -Encoding UTF8
CodePudding user response:
If you change the Attributes name from "CanonicalNameOfObject" to just "CanonicalName" you will receive the CN in string format.
Get-ADComputer -Filter * -Property * | Select-Object CanonicalName
CodePudding user response:
A "property value collection" is just that, a collection. You get that a lot in AD, every time an attribute takes more than one value (that is to say "most of the time").
Indexing is required even for singular items, eg. $AdUser.proxyAddresses[0]
; if you can't be certain there is just the one value then you'll need to iterate.
Note that you can check .PropertyNames for presence of the attribute you want - which is not necessarily a given - and that you can also use $UserObject[$propertyName]
syntax to access it.