With this script, the value for "enabled" is blank. How do I get it to show "true" or "false" in the export, if at all possible?
FunctionGet-Filtered{
#---------- All users
$strFilter="(&(objectClass=user)(objectCategory=person))"
#===============================================================================================================
# This section will open a window with the AD Structure listed. Select the OU you want to target and the filter selected will be targeted there
#===============================================================================================================
$GetADOU=Get-ADOrganizationalUnit-Filter*-properties* | Select canonicalname,DistinguishedName | sort-object canonicalname | Out-GridView-Title"Pick an OU"-passthru
$ADOU=$GetADOU.distinguishedname
#===============================================================================================================
# This section allows for searching AD
#===============================================================================================================
$objDomain=New-ObjectSystem.DirectoryServices.DirectoryEntry("LDAP://$ADOU")
$objSearcher=New-ObjectSystem.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot=$objDomain
$objSearcher.PageSize= 1000 #--if more than 1000 objects returned, you need to use the PageSize parameter set to 1000
$objSearcher.Filter=$strFilter
$objSearcher.SearchScope="Subtree"
#================================================================================================================
#list the attributes you're wanting
#================================================================================================================
$colProplist="name","displayname","samaccountname","mailnickname","mail","canonicalname","publicdelegates","title","description","department","enabled"
# create empty array
$objArray= @()
foreach ($iin$colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults=$objSearcher.FindAll()
foreach ($objResultin$colResults)
{$objItem=$objResult.Properties
$objItem.name
$objItem.displayname
$objItem.samaccountname
$objItem.mailnickname
$objItem.mail
$objItem.canonicalname
$objItem.publicdelegates
$objItem.title
$objItem.description
$objItem.department
$objItem.enabled
$ItemCol=""|select name,displayname,samaccountname,mailnickname,mail,canonicalname,publicdelegates,title,description,department,enabled
$ItemCol.name= [string]$objItem.name
$ItemCol.displayname= [string]$objItem.displayname
$ItemCol.samaccountname= [string]$objItem.samaccountname
$ItemCol.mailnickname= [string]$objItem.mailnickname
$ItemCol.mail= [string]$objItem.mail
$ItemCol.canonicalname= [string]$objItem.canonicalname
$ItemCol.publicDelegates= [string]$objItem.publicdelegates
$ItemCol.title= [string]$objItem.title
$ItemCol.description= [string]$objItem.description
$ItemCol.department= [string]$objItem.department
$ItemCol.enabled=$objItem.enabled
$objArray+=$ItemCol
}
$objArray | export-csv C:\scripts\reports\Users\accts.csv-NoTypeInformation
} # put a name for the file and the path above.
#---------- All users
$strFilter="(&(objectClass=user)(objectCategory=person))"
#===============================================================================================================
# This section will open a window with the AD Structure listed. Select the OU you want to target and the filter selected will be targeted there
#===============================================================================================================
$GetADOU=Get-ADOrganizationalUnit-Filter*-properties* | Select canonicalname,DistinguishedName | sort-object canonicalname | Out-GridView-Title"Pick an OU"-passthru
$ADOU=$GetADOU.distinguishedname
#===============================================================================================================
# This section allows for searching AD
#===============================================================================================================
$objDomain=New-ObjectSystem.DirectoryServices.DirectoryEntry("LDAP://$ADOU")
$objSearcher=New-ObjectSystem.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot=$objDomain
$objSearcher.PageSize= 1000 #--if more than 1000 objects returned, you need to use the PageSize parameter set to 1000
$objSearcher.Filter=$strFilter
$objSearcher.SearchScope="Subtree"
#================================================================================================================
#list the attributes you're wanting
#================================================================================================================
$colProplist="name","displayname","samaccountname","mailnickname","mail","canonicalname","publicdelegates","title","description","department","enabled"
# create empty array
$objArray= @()
foreach ($iin$colPropList){$objSearcher.PropertiesToLoad.Add($i)}
$colResults=$objSearcher.FindAll()
foreach ($objResultin$colResults)
{$objItem=$objResult.Properties
$objItem.name
$objItem.displayname
$objItem.samaccountname
$objItem.mailnickname
$objItem.mail
$objItem.canonicalname
$objItem.publicdelegates
$objItem.title
$objItem.description
$objItem.department
$objItem.enabled
$ItemCol=""|select name,displayname,samaccountname,mailnickname,mail,canonicalname,publicdelegates,title,description,department,enabled
$ItemCol.name= [string]$objItem.name
$ItemCol.displayname= [string]$objItem.displayname
$ItemCol.samaccountname= [string]$objItem.samaccountname
$ItemCol.mailnickname= [string]$objItem.mailnickname
$ItemCol.mail= [string]$objItem.mail
$ItemCol.canonicalname= [string]$objItem.canonicalname
$ItemCol.publicDelegates= [string]$objItem.publicdelegates
$ItemCol.title= [string]$objItem.title
$ItemCol.description= [string]$objItem.description
$ItemCol.department= [string]$objItem.department
$ItemCol.enabled=$objItem.enabled
$objArray+=$ItemCol
}
$objArray | export-csv C:\scripts\reports\Users\accts.csv-NoTypeInformation
} # put a name for the file and the path above.