@@ -2188,7 +2188,7 @@ filter Get-NetDomain {
2188
2188
[System.DirectoryServices.ActiveDirectory.Domain ]::GetDomain($DomainContext )
2189
2189
}
2190
2190
catch {
2191
- Write-Warning " The specified domain does '$Domain ' not exist, could not be contacted, there isn't an existing trust, or the specified credentials are invalid."
2191
+ Write-Verbose " The specified domain does '$Domain ' not exist, could not be contacted, there isn't an existing trust, or the specified credentials are invalid."
2192
2192
$Null
2193
2193
}
2194
2194
}
@@ -2198,7 +2198,7 @@ filter Get-NetDomain {
2198
2198
[System.DirectoryServices.ActiveDirectory.Domain ]::GetDomain($DomainContext )
2199
2199
}
2200
2200
catch {
2201
- Write-Warning " The specified domain '$Domain ' does not exist, could not be contacted, or there isn't an existing trust."
2201
+ Write-Verbose " The specified domain '$Domain ' does not exist, could not be contacted, or there isn't an existing trust."
2202
2202
$Null
2203
2203
}
2204
2204
}
@@ -2257,7 +2257,7 @@ filter Get-NetForest {
2257
2257
$ForestObject = [System.DirectoryServices.ActiveDirectory.Forest ]::GetForest($ForestContext )
2258
2258
}
2259
2259
catch {
2260
- Write-Warning " The specified forest '$Forest ' does not exist, could not be contacted, there isn't an existing trust, or the specified credentials are invalid."
2260
+ Write-Verbose " The specified forest '$Forest ' does not exist, could not be contacted, there isn't an existing trust, or the specified credentials are invalid."
2261
2261
$Null
2262
2262
}
2263
2263
}
@@ -2267,7 +2267,7 @@ filter Get-NetForest {
2267
2267
$ForestObject = [System.DirectoryServices.ActiveDirectory.Forest ]::GetForest($ForestContext )
2268
2268
}
2269
2269
catch {
2270
- Write-Warning " The specified forest '$Forest ' does not exist, could not be contacted, or there isn't an existing trust."
2270
+ Write-Verbose " The specified forest '$Forest ' does not exist, could not be contacted, or there isn't an existing trust."
2271
2271
return $Null
2272
2272
}
2273
2273
}
@@ -12514,6 +12514,22 @@ function Get-NetDomainTrust {
12514
12514
$Credential
12515
12515
)
12516
12516
12517
+ begin {
12518
+ $TrustAttributes = @ {
12519
+ [uint32 ]' 0x00000001' = ' non_transitive'
12520
+ [uint32 ]' 0x00000002' = ' uplevel_only'
12521
+ [uint32 ]' 0x00000004' = ' quarantined_domain'
12522
+ [uint32 ]' 0x00000008' = ' forest_transitive'
12523
+ [uint32 ]' 0x00000010' = ' cross_organization'
12524
+ [uint32 ]' 0x00000020' = ' within_forest'
12525
+ [uint32 ]' 0x00000040' = ' treat_as_external'
12526
+ [uint32 ]' 0x00000080' = ' trust_uses_rc4_encryption'
12527
+ [uint32 ]' 0x00000100' = ' trust_uses_aes_keys'
12528
+ [uint32 ]' 0x00000200' = ' cross_organization_no_tgt_delegation'
12529
+ [uint32 ]' 0x00000400' = ' pim_trust'
12530
+ }
12531
+ }
12532
+
12517
12533
process {
12518
12534
12519
12535
if (-not $Domain ) {
@@ -12532,33 +12548,21 @@ function Get-NetDomainTrust {
12532
12548
12533
12549
if ($TrustSearcher ) {
12534
12550
12535
- $TrustSearcher.filter = ' (&( objectClass=trustedDomain) )'
12551
+ $TrustSearcher.Filter = ' (objectClass=trustedDomain)'
12536
12552
12537
12553
$Results = $TrustSearcher.FindAll ()
12538
12554
$Results | Where-Object {$_ } | ForEach-Object {
12539
12555
$Props = $_.Properties
12540
12556
$DomainTrust = New-Object PSObject
12541
- $TrustAttrib = Switch ($Props.trustattributes )
12542
- {
12543
- 0x001 { " non_transitive" }
12544
- 0x002 { " uplevel_only" }
12545
- 0x004 { " quarantined_domain" }
12546
- 0x008 { " forest_transitive" }
12547
- 0x010 { " cross_organization" }
12548
- 0x020 { " within_forest" }
12549
- 0x040 { " treat_as_external" }
12550
- 0x080 { " trust_uses_rc4_encryption" }
12551
- 0x100 { " trust_uses_aes_keys" }
12552
- Default {
12553
- Write-Warning " Unknown trust attribute: $ ( $Props.trustattributes ) " ;
12554
- " $ ( $Props.trustattributes ) " ;
12555
- }
12556
- }
12557
+
12558
+ $TrustAttrib = @ ()
12559
+ $TrustAttrib += $TrustAttributes.Keys | Where-Object { $Props.trustattributes [0 ] -band $_ } | ForEach-Object { $TrustAttributes [$_ ] }
12560
+
12557
12561
$Direction = Switch ($Props.trustdirection ) {
12558
- 0 { " Disabled" }
12559
- 1 { " Inbound" }
12560
- 2 { " Outbound" }
12561
- 3 { " Bidirectional" }
12562
+ 0 { ' Disabled' }
12563
+ 1 { ' Inbound' }
12564
+ 2 { ' Outbound' }
12565
+ 3 { ' Bidirectional' }
12562
12566
}
12563
12567
$ObjectGuid = New-Object Guid @ (, $Props.objectguid [0 ])
12564
12568
$TargetSID = (New-Object System.Security.Principal.SecurityIdentifier($Props.securityidentifier [0 ], 0 )).Value
@@ -12567,7 +12571,7 @@ function Get-NetDomainTrust {
12567
12571
$DomainTrust | Add-Member Noteproperty ' TargetName' $Props.name [0 ]
12568
12572
$DomainTrust | Add-Member Noteproperty ' TargetSID' $TargetSID
12569
12573
$DomainTrust | Add-Member Noteproperty ' ObjectGuid' " {$ObjectGuid }"
12570
- $DomainTrust | Add-Member Noteproperty ' TrustType' " $ TrustAttrib"
12574
+ $DomainTrust | Add-Member Noteproperty ' TrustType' $ ( $ TrustAttrib -join ' , ' )
12571
12575
$DomainTrust | Add-Member Noteproperty ' TrustDirection' " $Direction "
12572
12576
$DomainTrust
12573
12577
}
@@ -12639,7 +12643,7 @@ function Get-NetDomainTrust {
12639
12643
}
12640
12644
}
12641
12645
else {
12642
- Write-Error " Could not retrieve domain controller for $Domain "
12646
+ Write-Verbose " Could not retrieve domain controller for $Domain "
12643
12647
}
12644
12648
}
12645
12649
else {
@@ -13124,34 +13128,41 @@ function Invoke-MapDomainTrust {
13124
13128
}
13125
13129
13126
13130
# get any forest trusts, if they exist
13127
- $Trusts += Get-NetForestTrust - Forest $Domain - Credential $Credential
13131
+ if (-not ($LDAP -or $DomainController ) ) {
13132
+ $Trusts += Get-NetForestTrust - Forest $Domain - Credential $Credential
13133
+ }
13128
13134
13129
13135
if ($Trusts ) {
13136
+ if ($Trusts -isnot [System.Array ]) {
13137
+ $Trusts = @ ($Trusts )
13138
+ }
13130
13139
13131
13140
# enumerate each trust found
13132
13141
ForEach ($Trust in $Trusts ) {
13133
- $SourceDomain = $Trust.SourceName
13134
- $TargetDomain = $Trust.TargetName
13135
- $TrustType = $Trust.TrustType
13136
- $TrustDirection = $Trust.TrustDirection
13137
-
13138
- # make sure we process the target
13139
- $Null = $Domains.push ($TargetDomain )
13140
-
13141
- # build the nicely-parsable custom output object
13142
- $DomainTrust = New-Object PSObject
13143
- $DomainTrust | Add-Member Noteproperty ' SourceDomain' " $SourceDomain "
13144
- $DomainTrust | Add-Member Noteproperty ' SourceSID' $Trust.SourceSID
13145
- $DomainTrust | Add-Member Noteproperty ' TargetDomain' " $TargetDomain "
13146
- $DomainTrust | Add-Member Noteproperty ' TargetSID' $Trust.TargetSID
13147
- $DomainTrust | Add-Member Noteproperty ' TrustType' " $TrustType "
13148
- $DomainTrust | Add-Member Noteproperty ' TrustDirection' " $TrustDirection "
13149
- $DomainTrust
13142
+ if ($Trust.SourceName -and $Trust.TargetName ) {
13143
+ $SourceDomain = $Trust.SourceName
13144
+ $TargetDomain = $Trust.TargetName
13145
+ $TrustType = $Trust.TrustType
13146
+ $TrustDirection = $Trust.TrustDirection
13147
+
13148
+ # make sure we process the target
13149
+ $Null = $Domains.push ($TargetDomain )
13150
+
13151
+ # build the nicely-parsable custom output object
13152
+ $DomainTrust = New-Object PSObject
13153
+ $DomainTrust | Add-Member Noteproperty ' SourceDomain' " $SourceDomain "
13154
+ $DomainTrust | Add-Member Noteproperty ' SourceSID' $Trust.SourceSID
13155
+ $DomainTrust | Add-Member Noteproperty ' TargetDomain' " $TargetDomain "
13156
+ $DomainTrust | Add-Member Noteproperty ' TargetSID' $Trust.TargetSID
13157
+ $DomainTrust | Add-Member Noteproperty ' TrustType' " $TrustType "
13158
+ $DomainTrust | Add-Member Noteproperty ' TrustDirection' " $TrustDirection "
13159
+ $DomainTrust
13160
+ }
13150
13161
}
13151
13162
}
13152
13163
}
13153
13164
catch {
13154
- Write-Warning " [!] Error: $_ "
13165
+ Write-Verbose " [!] Error: $_ "
13155
13166
}
13156
13167
}
13157
13168
}
0 commit comments