@@ -1713,6 +1713,7 @@ filter Get-DomainSearcher {
1713
1713
}
1714
1714
}
1715
1715
elseif (-not $DomainController ) {
1716
+ # if a DC isn't specified
1716
1717
try {
1717
1718
$DomainController = ((Get-NetDomain - Credential $Credential ).PdcRoleOwner).Name
1718
1719
}
@@ -4987,6 +4988,10 @@ function Get-DomainSID {
4987
4988
4988
4989
The domain to query, defaults to the current domain.
4989
4990
4991
+ . PARAMETER DomainController
4992
+
4993
+ Domain controller to reflect LDAP queries through.
4994
+
4990
4995
. EXAMPLE
4991
4996
4992
4997
C:\> Get-DomainSID -Domain TEST
@@ -4996,16 +5001,15 @@ function Get-DomainSID {
4996
5001
4997
5002
param (
4998
5003
[String ]
4999
- $Domain
5004
+ $Domain ,
5005
+
5006
+ [String ]
5007
+ $DomainController
5000
5008
)
5001
5009
5002
- $FoundDomain = Get-NetDomain - Domain $Domain
5003
-
5004
- if ($FoundDomain ) {
5005
- # query for the primary domain controller so we can extract the domain SID for filtering
5006
- $PrimaryDC = $FoundDomain.PdcRoleOwner
5007
- $PrimaryDCSID = (Get-NetComputer - Domain $Domain - ComputerName $PrimaryDC - FullData).objectsid
5008
- $Parts = $PrimaryDCSID.split (" -" )
5010
+ $DCSID = Get-NetComputer - Domain $Domain - DomainController $DomainController - FullData - Filter ' (userAccountControl:1.2.840.113556.1.4.803:=8192)' | Select-Object - First 1 - ExpandProperty objectsid
5011
+ if ($DCSID ) {
5012
+ $Parts = $DCSID.split (" -" )
5009
5013
$Parts [0 .. ($Parts.length -2 )] -join " -"
5010
5014
}
5011
5015
}
@@ -5342,7 +5346,7 @@ function Get-NetGroupMember {
5342
5346
}
5343
5347
else {
5344
5348
# default to domain admins
5345
- $SID = (Get-DomainSID - Domain $TargetDomain - Credential $Credential ) + " -512"
5349
+ $SID = (Get-DomainSID - Domain $TargetDomain - DomainController $TargetDomainController ) + " -512"
5346
5350
$Group = Get-NetGroup - SID $SID - Domain $TargetDomain - DomainController $TargetDomainController - Credential $Credential - FullData - PageSize $PageSize
5347
5351
}
5348
5352
$GroupDN = $Group.distinguishedname
@@ -5368,7 +5372,7 @@ function Get-NetGroupMember {
5368
5372
}
5369
5373
else {
5370
5374
# default to domain admins
5371
- $SID = (Get-DomainSID - Domain $TargetDomain - Credential $Credential ) + " -512"
5375
+ $SID = (Get-DomainSID - Domain $TargetDomain - DomainController $TargetDomainController ) + " -512"
5372
5376
$GroupSearcher.filter = " (&(objectCategory=group)(objectSID=$SID )$Filter )"
5373
5377
}
5374
5378
@@ -12288,7 +12292,7 @@ function Invoke-EnumerateLocalAdmin {
12288
12292
}
12289
12293
12290
12294
# query for the primary domain controller so we can extract the domain SID for filtering
12291
- $DomainSID = Get-DomainSID - Domain $Domain
12295
+ $DomainSID = Get-DomainSID - Domain $Domain - DomainController $DomainController
12292
12296
}
12293
12297
12294
12298
# script block that enumerates a server
@@ -12466,7 +12470,7 @@ function Get-NetDomainTrust {
12466
12470
12467
12471
[CmdletBinding ()]
12468
12472
param (
12469
- [Parameter (Position = 0 , ValueFromPipeline = $True )]
12473
+ [Parameter (Position = 0 , ValueFromPipeline = $True )]
12470
12474
[String ]
12471
12475
$Domain ,
12472
12476
@@ -12492,14 +12496,19 @@ function Get-NetDomainTrust {
12492
12496
12493
12497
process {
12494
12498
12495
- if ((-not $Domain ) -or ((-not $API ) -and (-not $DomainController ))) {
12496
- $Domain = (Get-NetDomain - Credential $Credential ).Name
12499
+ if (-not $Domain ) {
12500
+ # if not domain is specified grab the current domain
12501
+ $SourceDomain = (Get-NetDomain - Credential $Credential ).Name
12497
12502
}
12503
+ else {
12504
+ $SourceDomain = $Domain
12505
+ }
12506
+
12507
+ if ($LDAP -or $ADSPath ) {
12498
12508
12499
- if ( $LDAP ) {
12509
+ $TrustSearcher = Get-DomainSearcher - Domain $SourceDomain - DomainController $DomainController - Credential $Credential - PageSize $PageSize - ADSpath $ADSpath
12500
12510
12501
- $TrustSearcher = Get-DomainSearcher - Domain $Domain - DomainController $DomainController - Credential $Credential - PageSize $PageSize - ADSpath $ADSpath
12502
- $SourceSID = Get-DomainSID - Domain $Domain - DomainController $DomainController
12511
+ $SourceSID = Get-DomainSID - Domain $SourceDomain - DomainController $DomainController
12503
12512
12504
12513
if ($TrustSearcher ) {
12505
12514
@@ -12533,7 +12542,7 @@ function Get-NetDomainTrust {
12533
12542
}
12534
12543
$ObjectGuid = New-Object Guid @ (, $Props.objectguid [0 ])
12535
12544
$TargetSID = (New-Object System.Security.Principal.SecurityIdentifier($Props.securityidentifier [0 ], 0 )).Value
12536
- $DomainTrust | Add-Member Noteproperty ' SourceName' $Domain
12545
+ $DomainTrust | Add-Member Noteproperty ' SourceName' $SourceDomain
12537
12546
$DomainTrust | Add-Member Noteproperty ' SourceSID' $SourceSID
12538
12547
$DomainTrust | Add-Member Noteproperty ' TargetName' $Props.name [0 ]
12539
12548
$DomainTrust | Add-Member Noteproperty ' TargetSID' $TargetSID
@@ -12548,7 +12557,7 @@ function Get-NetDomainTrust {
12548
12557
}
12549
12558
elseif ($API ) {
12550
12559
if (-not $DomainController ) {
12551
- $DomainController = Get-NetDomainController - Credential $Credential - Domain $Domain | Select-Object - First 1 | Select-Object - ExpandProperty Name
12560
+ $DomainController = Get-NetDomainController - Credential $Credential - Domain $SourceDomain | Select-Object - First 1 | Select-Object - ExpandProperty Name
12552
12561
}
12553
12562
12554
12563
if ($DomainController ) {
@@ -12588,7 +12597,7 @@ function Get-NetDomainTrust {
12588
12597
}
12589
12598
else {
12590
12599
$DomainTrust = New-Object PSObject
12591
- $DomainTrust | Add-Member Noteproperty ' SourceDomain' $Domain
12600
+ $DomainTrust | Add-Member Noteproperty ' SourceDomain' $SourceDomain
12592
12601
$DomainTrust | Add-Member Noteproperty ' SourceDomainController' $DomainController
12593
12602
$DomainTrust | Add-Member Noteproperty ' NetbiosDomainName' $Info.NetbiosDomainName
12594
12603
$DomainTrust | Add-Member Noteproperty ' DnsDomainName' $Info.DnsDomainName
0 commit comments