Out-String a result of a CMDLET and manipulate it in PowerShell -
i have variable gives me canocical name of object in active directory:
$lastou = get-adorganizationalunit -filter * -properties * | sort { $_.whencreated } -descending | select -first 1 {$_.canonicalname} | out-string if run command write-host $lastouit indeeds gives me result expected:
@{$_.canonicalname=domain.local/microsoft/userz}
what i'm trying manipulate string have
microsoft
selected.
i used out-string method have result of command string.
after, use .split()-function manipulate result.
i $compname = $lastou.split(...).
however error:
method invocation failed because [selected.microsoft.activedirectory.management.adorganizationalunit] not contain method named 'split'.
this means result not string? wrong in command?
change select statement include -expandproperty, should give string instead of object.
change this
select -first 1 {$_.canonicalname} |out-string to this
select -expandproperty canonicalname -first 1
Comments
Post a Comment