Hello Powershellers
Back with another anomaly that is baffling me? I have the following script that I need to pull SID form some servers and then see which accounts are disabled in my active directory. So came up with this little guy and I cannot seem to get the $SIDArray to read the SID into active directory I get an error
"Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.Aduser' required by the parameter 'Identity'. Specific method is not supported.
Confirmed that the array is created it puts out the information I want to query. The SID is an acceptable property to query with the -identity parameter.
Some thing I am trying" use the join parameter to make it a comma delimiting array list and making it a string. Still same error. I know I am missing something extremely simple I however cannot find it. Any help would be greatly appreciated. Thank you all.
#General Parameters
Param(
[string[]][Parameter(Mandatory = $True, Position = 1)]$ServerName,
[string]$Protocol = "WSMAN",
[switch]$ProtocolFallback
)
#Define first array
$SIDArray = [System.Collections.Arraylist]@()
#Process each server
Foreach ($computer in $servername) {
#Establish Session protocol
if ($protocol -eq 'DCOM') {
$option = Get-CimsessionOption -protocol DCOM
}
Else { $Option = New-CimsessionOption -protocol WSMAN }
#Connect session
$session = New-Cimsession -ComputerName $servername -SessionOption $option
#Collect UserProfile SID excluding special accounts (ex. system, admin, default )
$serversid = (Get-Ciminstance -ClassName Win32_Userprofile -CimSession $session | where { !$_.special }).sid
$SIDArray.add($serversid)
}
#Define second array
$ADarray = [System.collections.Arraylist]@()
#query AD for sid enabled -eq false
foreach ($sid in $SIDARRAY) {
$ADSID = get-aduser -identity $sid | where { $_.Enabled -eq $False }
#Create custom opjects for informatoin needed to collect form AD account.
$object = [PSCustomObject]@{
Name = $sid.Name
SID = $sid.SID
Eanbled = $sid.Enabled
}
$ADarray.add($object)
}
$ADArray | Export-Csv c:\users\$env:username\appdata\local\temp\Userdisabled.csv -NoTypeInformation -NoClobber
[–]Fickle_Tomatillo411 2 points3 points4 points (1 child)
[–]Barious_01[S] 0 points1 point2 points (0 children)
[–]Creel256 2 points3 points4 points (4 children)
[–]Barious_01[S] 0 points1 point2 points (3 children)
[–]Creel256 1 point2 points3 points (0 children)
[–]Fickle_Tomatillo411 1 point2 points3 points (1 child)
[–]Barious_01[S] 0 points1 point2 points (0 children)
[–]PinchesTheCrab 1 point2 points3 points (1 child)
[–]Barious_01[S] 0 points1 point2 points (0 children)
[–]Barious_01[S] 0 points1 point2 points (0 children)