Hi guys,
I’m trying to modify a script I found here, to be based on the AD Groups a user account is a member of. This is what I’ve got, but I don’t think it’s returning the group membership correctly:
[CmdletBinding()]
param (
[string]$SiteCode,
[string]$SiteServer,
[string]$Domain
)
$ResourceName = $env:computername
$Prefix = "A."
$Suffix = ".i"
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$PrimaryUsers = (Get-WmiObject -ComputerName $SiteServer -Class SMS_UserMachineRelationship -Namespace root\SMS\Site_$SiteCode -Filter "ResourceName='$ResourceName' and IsActive='1' and Types='1'").UniqueUserName.replace("$Domain\","")
if ($PrimaryUsers -ne $null) {
foreach ($PrimaryUser in $PrimaryUsers){
"primary user: " + $primaryuser
$ADObjectDN = ([ADSISEARCHER]"samaccountname=$PrimaryUser").Findone().Properties.distinguishedname
"ADObjectDN: " + $ADObjectDN
$AllGroups =([ADSISEARCHER]"member:1.2.840.113556.1.4.1941:=$ADObjectDN").FindAll()
}
}
"AllGroups: " + $AllGroups
$DescList = $AllGroups.Path `
| Where { ($_ -replace '^LDAP://CN=([^,]+).+$','$1').StartsWith($Prefix) -and ($_ -replace '^LDAP://CN=([^,]+).+$','$1').EndsWith($Suffix) } `
| Foreach { ([ADSI]"$_").Description }
$AppCount = 1
$DescList | Foreach { $tsenv.Value("COALESCEDAPPS" + ($AppCount++).ToString("00")) = "$_" }
"DescList: " + $DescList
Thanks,
Gregor