@@ -895,7 +895,7 @@ filter Convert-NameToSid {
895
895
$Domain = $ObjectName.Split (" \" )[0 ]
896
896
$ObjectName = $ObjectName.Split (" \" )[1 ]
897
897
}
898
- elseif (! $Domain ) {
898
+ elseif (-not $Domain ) {
899
899
$Domain = (Get-NetDomain ).Name
900
900
}
901
901
@@ -1698,11 +1698,11 @@ filter Get-DomainSearcher {
1698
1698
$Credential
1699
1699
)
1700
1700
1701
- if (! $Credential ) {
1702
- if (! $Domain ) {
1701
+ if (-not $Credential ) {
1702
+ if (-not $Domain ) {
1703
1703
$Domain = (Get-NetDomain ).name
1704
1704
}
1705
- elseif (! $DomainController ) {
1705
+ elseif (-not $DomainController ) {
1706
1706
try {
1707
1707
# if there's no -DomainController specified, try to pull the primary DC to reflect queries through
1708
1708
$DomainController = ((Get-NetDomain ).PdcRoleOwner).Name
@@ -1712,7 +1712,7 @@ filter Get-DomainSearcher {
1712
1712
}
1713
1713
}
1714
1714
}
1715
- elseif (! $DomainController ) {
1715
+ elseif (-not $DomainController ) {
1716
1716
try {
1717
1717
$DomainController = ((Get-NetDomain - Credential $Credential ).PdcRoleOwner).Name
1718
1718
}
@@ -1730,24 +1730,24 @@ filter Get-DomainSearcher {
1730
1730
if ($DomainController ) {
1731
1731
$SearchString += $DomainController
1732
1732
if ($Domain ){
1733
- $SearchString += " / "
1733
+ $SearchString += ' / '
1734
1734
}
1735
1735
}
1736
1736
1737
1737
if ($ADSprefix ) {
1738
- $SearchString += $ADSprefix + " , "
1738
+ $SearchString += $ADSprefix + ' , '
1739
1739
}
1740
1740
1741
1741
if ($ADSpath ) {
1742
- if ($ADSpath -like " GC://* " ) {
1742
+ if ($ADSpath -Match ' ^ GC://' ) {
1743
1743
# if we're searching the global catalog
1744
- $DN = $AdsPath
1745
- $SearchString = " "
1744
+ $DN = $AdsPath.ToUpper ().Trim( ' / ' )
1745
+ $SearchString = ' '
1746
1746
}
1747
1747
else {
1748
- if ($ADSpath -like " LDAP://* " ) {
1748
+ if ($ADSpath -match ' ^ LDAP://' ) {
1749
1749
if ($ADSpath -match " LDAP://.+/.+" ) {
1750
- $SearchString = " "
1750
+ $SearchString = ' '
1751
1751
}
1752
1752
else {
1753
1753
$ADSpath = $ADSpath.Substring (7 )
@@ -4851,7 +4851,7 @@ function Get-NetSite {
4851
4851
$SiteSearcher.dispose ()
4852
4852
}
4853
4853
catch {
4854
- Write-Warning $_
4854
+ Write-Verbose $_
4855
4855
}
4856
4856
}
4857
4857
}
@@ -6351,8 +6351,23 @@ function Get-NetGPO {
6351
6351
try {
6352
6352
$Results = $GPOSearcher.FindAll ()
6353
6353
$Results | Where-Object {$_ } | ForEach-Object {
6354
- # convert/process the LDAP fields for each result
6355
- Convert-LDAPProperty - Properties $_.Properties
6354
+ if ($ADSPath -and ($ADSpath -Match ' ^GC://' )) {
6355
+ $Properties = Convert-LDAPProperty - Properties $_.Properties
6356
+ try {
6357
+ $GPODN = $Properties.distinguishedname
6358
+ $GPODomain = $GPODN.subString ($GPODN.IndexOf (" DC=" )) -replace ' DC=' , ' ' -replace ' ,' , ' .'
6359
+ $gpcfilesyspath = " \\$GPODomain \SysVol\$GPODomain \Policies\$ ( $Properties.cn ) "
6360
+ $Properties | Add-Member Noteproperty ' gpcfilesyspath' $gpcfilesyspath
6361
+ $Properties
6362
+ }
6363
+ catch {
6364
+ $Properties
6365
+ }
6366
+ }
6367
+ else {
6368
+ # convert/process the LDAP fields for each result
6369
+ Convert-LDAPProperty - Properties $_.Properties
6370
+ }
6356
6371
}
6357
6372
$Results.dispose ()
6358
6373
$GPOSearcher.dispose ()
@@ -6710,7 +6725,7 @@ function Get-NetGPOGroup {
6710
6725
ForEach ($Member in $MembershipValue ) {
6711
6726
if ($Member -and ($Member.Trim () -ne ' ' )) {
6712
6727
if ($Member -notmatch ' ^S-1-.*' ) {
6713
- $MemberSID = Convert-NameToSid - ObjectName $Member | Select-Object - ExpandProperty SID
6728
+ $MemberSID = Convert-NameToSid - Domain $Domain - ObjectName $Member | Select-Object - ExpandProperty SID
6714
6729
if ($MemberSID ) {
6715
6730
$GroupMembers += $MemberSID
6716
6731
}
@@ -6729,6 +6744,7 @@ function Get-NetGPOGroup {
6729
6744
if (-not $Memberships [$Group ]) {
6730
6745
$Memberships [$Group ] = @ {}
6731
6746
}
6747
+ if ($MembershipValue -isnot [System.Array ]) {$MembershipValue = @ ($MembershipValue )}
6732
6748
$Memberships [$Group ].Add($Relation , $MembershipValue )
6733
6749
}
6734
6750
@@ -6757,7 +6773,7 @@ function Get-NetGPOGroup {
6757
6773
$GroupSID = ' S-1-5-32-546'
6758
6774
}
6759
6775
elseif ($GroupName.Trim () -ne ' ' ) {
6760
- $GroupSID = Convert-NameToSid - ObjectName $Groupname | Select-Object - ExpandProperty SID
6776
+ $GroupSID = Convert-NameToSid - Domain $Domain - ObjectName $Groupname | Select-Object - ExpandProperty SID
6761
6777
}
6762
6778
else {
6763
6779
$GroupSID = $Null
@@ -6791,7 +6807,7 @@ function Get-NetGPOGroup {
6791
6807
if ($Member -and ($Member.Trim () -ne ' ' )) {
6792
6808
if ($Member -notmatch ' ^S-1-.*' ) {
6793
6809
# if the resulting member is username and not a SID, attempt to resolve it
6794
- $MemberSID = Convert-NameToSid - ObjectName $Member | Select-Object - ExpandProperty SID
6810
+ $MemberSID = Convert-NameToSid - Domain $Domain - ObjectName $Member | Select-Object - ExpandProperty SID
6795
6811
if ($MemberSID ) {
6796
6812
$GroupMembers += $MemberSID
6797
6813
}
@@ -6933,7 +6949,7 @@ function Find-GPOLocation {
6933
6949
6934
6950
if ($UserName ) {
6935
6951
# if a group name is specified, get that user object so we can extract the target SID
6936
- $User = Get-NetUser - UserName $UserName - Domain $Domain - DomainController $DomainController - PageSize $PageSize
6952
+ $User = Get-NetUser - UserName $UserName - Domain $Domain - DomainController $DomainController - PageSize $PageSize | Select-Object - First 1
6937
6953
$UserSid = $User.objectsid
6938
6954
6939
6955
if (-not $UserSid ) {
@@ -6946,7 +6962,7 @@ function Find-GPOLocation {
6946
6962
}
6947
6963
elseif ($GroupName ) {
6948
6964
# if a group name is specified, get that group object so we can extract the target SID
6949
- $Group = Get-NetGroup - GroupName $GroupName - Domain $Domain - DomainController $DomainController - FullData - PageSize $PageSize
6965
+ $Group = Get-NetGroup - GroupName $GroupName - Domain $Domain - DomainController $DomainController - FullData - PageSize $PageSize | Select-Object - First 1
6950
6966
$GroupSid = $Group.objectsid
6951
6967
6952
6968
if (-not $GroupSid ) {
@@ -7046,15 +7062,15 @@ function Find-GPOLocation {
7046
7062
if ($OUComputers -isnot [System.Array ]) {$OUComputers = @ ($OUComputers )}
7047
7063
7048
7064
ForEach ($TargetSid in $TargetObjectSIDs ) {
7049
-
7050
- $Object = Get-ADObject - SID $TargetSid - Domain $Domain - DomainController $DomainController $_ - PageSize $PageSize
7065
+ $Object = Get-ADObject - SID $TargetSid - Domain $Domain - DomainController $DomainController - Credential $Credential - PageSize $PageSize
7051
7066
7052
7067
$IsGroup = @ (' 268435456' , ' 268435457' , ' 536870912' , ' 536870913' ) -contains $Object.samaccounttype
7053
7068
7054
7069
$GPOLocation = New-Object PSObject
7055
7070
$GPOLocation | Add-Member Noteproperty ' ObjectName' $Object.samaccountname
7056
7071
$GPOLocation | Add-Member Noteproperty ' ObjectDN' $Object.distinguishedname
7057
7072
$GPOLocation | Add-Member Noteproperty ' ObjectSID' $Object.objectsid
7073
+ $GPOLocation | Add-Member Noteproperty ' Domain' $Domain
7058
7074
$GPOLocation | Add-Member Noteproperty ' IsGroup' $IsGroup
7059
7075
$GPOLocation | Add-Member Noteproperty ' GPODisplayName' $GPOname
7060
7076
$GPOLocation | Add-Member Noteproperty ' GPOGuid' $GPOGuid
@@ -7070,7 +7086,7 @@ function Find-GPOLocation {
7070
7086
Get-NetSite - Domain $Domain - DomainController $DomainController - GUID $GPOguid - PageSize $PageSize - FullData | ForEach-Object {
7071
7087
7072
7088
ForEach ($TargetSid in $TargetObjectSIDs ) {
7073
- $Object = Get-ADObject - SID $TargetSid - Domain $Domain - DomainController $DomainController $_ - PageSize $PageSize
7089
+ $Object = Get-ADObject - SID $TargetSid - Domain $Domain - DomainController $DomainController - Credential $Credential - PageSize $PageSize
7074
7090
7075
7091
$IsGroup = @ (' 268435456' , ' 268435457' , ' 536870912' , ' 536870913' ) -contains $Object.samaccounttype
7076
7092
@@ -7079,6 +7095,7 @@ function Find-GPOLocation {
7079
7095
$AppliedSite | Add-Member Noteproperty ' ObjectDN' $Object.distinguishedname
7080
7096
$AppliedSite | Add-Member Noteproperty ' ObjectSID' $Object.objectsid
7081
7097
$AppliedSite | Add-Member Noteproperty ' IsGroup' $IsGroup
7098
+ $AppliedSite | Add-Member Noteproperty ' Domain' $Domain
7082
7099
$AppliedSite | Add-Member Noteproperty ' GPODisplayName' $GPOname
7083
7100
$AppliedSite | Add-Member Noteproperty ' GPOGuid' $GPOGuid
7084
7101
$AppliedSite | Add-Member Noteproperty ' GPOPath' $GPOPath
@@ -12396,6 +12413,11 @@ function Get-NetDomainTrust {
12396
12413
12397
12414
Domain controller to reflect LDAP queries through.
12398
12415
12416
+ . PARAMETER ADSpath
12417
+
12418
+ The LDAP source to search through, e.g. "LDAP://DC=testlab,DC=local".
12419
+ Useful for global catalog queries ;)
12420
+
12399
12421
. PARAMETER API
12400
12422
12401
12423
Use an API call (DsEnumerateDomainTrusts) to enumerate the trusts.
@@ -12451,6 +12473,9 @@ function Get-NetDomainTrust {
12451
12473
[String ]
12452
12474
$DomainController ,
12453
12475
12476
+ [String ]
12477
+ $ADSpath ,
12478
+
12454
12479
[Switch ]
12455
12480
$API ,
12456
12481
@@ -12473,7 +12498,7 @@ function Get-NetDomainTrust {
12473
12498
12474
12499
if ($LDAP ) {
12475
12500
12476
- $TrustSearcher = Get-DomainSearcher - Domain $Domain - DomainController $DomainController - Credential $Credential - PageSize $PageSize
12501
+ $TrustSearcher = Get-DomainSearcher - Domain $Domain - DomainController $DomainController - Credential $Credential - PageSize $PageSize - ADSpath $ADSpath
12477
12502
$SourceSID = Get-DomainSID - Domain $Domain - DomainController $DomainController
12478
12503
12479
12504
if ($TrustSearcher ) {
0 commit comments