Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Using ADSI - Need To Convert objectGUID To Match Get-ADUser Format (With Hyphens)

$
0
0

Hello,

I was previously generating a list of users for a browser based application, via theGet-ADUser cmdlet and using the objectGUID property.

$Today = (Get-Date)
$domain ="fabrikam.com:636"
$data += Get-ADUser -Server $domain -Filter {(Memberof -eq "CN=Software_AccessGroup,OU=UserAccounts,DC=FABRIKAM,DC=COM") -and (Enabled -eq $true) -and (-Not (AccountExpirationDate -lt $Today)) -and (sAMAccountName -notlike "*_*")} -Properties objectGUID, sAMAccountName | select objectGUID, sAMAccountName}
$data | Export-Csv "C:\Temp\Users.csv" -NoTypeInformation

I have a new requirement to communicate with Active Directory via port 636, so I stopped using the Get-ADUser cmdlet, and are using [ADSI] instead.

([adsi]"LDAP://Hostname:636/CN=Software_AccessGroup,OU=UserAccounts,DC=FABRIKAM,DC=COM").member |
    ForEach-Object {[adsi]"LDAP://$_"} |
    select @{L="sAMAccountName";E={$_.sAMAccountName}},@{L="objectGUID";E={$_.objectGUID}}}  |
    Export-Csv "C:\Temp\Users.csv" -NoTypeInformation

Unfortunately the value returned by objectGUID via [ADSI] is in a different format, I need it to match what was returned by Get-ADUser as this is being used as the primary key in the database table to identify the existing users. Does anyone know how to convert this objectGUID value returned by [ADSI] so it matches?

Thanks

Stuart


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>