I created a PS script to find GPOs linked in an OU and subOUs, what am I doing wrong? I get this error and am confused about the message:
Get-ADOrganizationalUnit : Cannot bind parameter 'Identity'. Cannot convert the "@{DistinguishedName=OU=Windows 7,DC=domain,DC=com}" value of type "Selected.Microsoft.ActiveDirectory.Management.ADOrganizationalUnit" to type "Microsoft.ActiveDirectory.Management.ADOrganization alUnit". At F:\Untitled4.ps1:11 char:39 + $LinkedGPOs = Get-ADOrganizationalUnit <<<< $OU | select-object -ExpandProperty LinkedGroupPolicyObjects + CategoryInfo : InvalidArgument: (:) [Get-ADOrganizationalUnit], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.GetADOrganizationalUnit
get-module activedirectory,grouppolicy
$exportFilePath = "c:\temp\AllGPOsWin7-report date $(get-date -f dd-MM-yyyy).csv"
$OU = "ou=Windows 7,dc=domain,dc=com"
$AllSubOU = Get-ADOrganizationalUnit -SearchBase $OU -SearchScope Subtree -Filter * |
Select-Object DistinguishedName
foreach ($OU in $AllSubOU){
$OU
$LinkedGPOs = Get-ADOrganizationalUnit $OU | select-object -ExpandProperty LinkedGroupPolicyObjects
$LinkedGPOGUID = $LinkedGPOs | foreach-object{$_.substring(4,36)}
$GPOName = $LinkedGPOGUID | foreach-object{get-gpo -guid $_ | select-object displayname}
$OU,$ListGPO -join "," | Out-File -FilePath $exportFilePath -Append -Width 200