Skip to content

Commit a8187bd

Browse files
committed
PSSA
1 parent 549544e commit a8187bd

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
<#
22
.SYNOPSIS
3-
Loop through a list of specified domain controllers, and then loop through all DNS Server zones on each domain controller to make desired changes.
3+
Loop through a list of specified domain controllers, and then loop through all DNS Server zones on each domain
4+
controller to make desired changes.
45
56
.DESCRIPTION
6-
This script was written to change the Secondary Servers setting and the SecureSecondaries setting on all DNS zones on all DNS Servers (all domain controllers,
7-
in our environment.) It provides an ideal way to adjust settings for one (or all) zones across every zone server, because some settings are stored individually
8-
in each server's registry, and not completed replicated, even when the zone is AD-integrated.
7+
This script was written to change the Secondary Servers setting and the SecureSecondaries setting on all DNS zones on
8+
all DNS Servers (all domain controllers, in our environment.) It provides an ideal way to adjust settings for one (or
9+
all) zones across every zone server, because some settings are stored individually in each server's registry, and not
10+
completed replicated, even when the zone is AD-integrated.
911
10-
Our servers actually havce Remote Registry access disabled, so the remote part of this script will not work, but the inner loop beginning with the collection
11-
of zones ("$zones = Get-ChildItem ...") from the registry can be run manually on each DNS Server, still saving time and providing more accuracy than multiple
12-
manual changes could.
12+
Our servers actually have Remote Registry access disabled, so the remote part of this script will not work, but the
13+
inner loop beginning with the collection of zones ("$zones = Get-ChildItem ...") from the registry can be run manually
14+
on each DNS Server, still saving time and providing more accuracy than multiple manual changes could.
1315
1416
.NOTES
15-
Be sure to test your changes first by using -WhatIf on the Set-ItemProperty cmdlets, and also by testing your changes manually with at least one zone. Check the
16-
registry and the GUI after running your script, and note that changing some zone settings via the registry will require the DNS Server service to be restarted
17-
in order for those changes to be read and take effect.
17+
Be sure to test your changes first by using -WhatIf on the Set-ItemProperty cmdlets, and also by testing your changes
18+
manually with at least one zone. Check the registry and the GUI after running your script, and note that changing some
19+
zone settings via the registry will require the DNS Server service to be restarted in order for those changes to be read
20+
and take effect.
1821
#>
1922

2023
if ($session) { Remove-PSSession $session }
2124

2225
#Specify a list of DNS servers manually, or just get a list of all domain controllers in the domain.
2326
#$servers = @("","","","","")
2427
$servers = Get-ADDomainController -Filter * | Select-Object Hostname
25-
$creds = Get-Credential
28+
$Creds = Get-Credential
2629
#Loop through each server in the list, opening a PowerShell remoting session, then show the name and status of the session. Skips (continue) to the next server if a connection fails.
2730
foreach ($srv in $servers) {
2831
$server = $srv.Hostname
29-
$session = New-PSSession -ComputerName $server -Name $server -Credential $creds
32+
$session = New-PSSession -ComputerName $server -Name $server -Credential $Creds
3033
Try {
3134
Write-Host -ForegroundColor Green "Connecting to $server... " -NoNewline
3235
Enter-PSSession $session
@@ -39,17 +42,16 @@ foreach ($srv in $servers) {
3942
$zones = Get-ChildItem -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\DNS Server\Zones\'
4043

4144
foreach ($zone in $zones) {
42-
Write-Host -NoNewline -ForegroundColor Yellow `n`n 'Name: ' (Get-ItemProperty -PSPath $zone.PSPath).PSChildName
43-
Write-Host -NoNewline `n 'SecondaryServers: ' (Get-ItemProperty -PSPath $zone.PSPath).SecondaryServers
44-
Write-Host -NoNewline `n 'SecureSecondaries: ' (Get-ItemProperty -PSPath $zone.PSPath).SecureSecondaries `n
45+
Write-Host "`n`n 'Name: ' (Get-ItemProperty -PSPath $zone.PSPath).PSChildName" -NoNewline -ForegroundColor Yellow
46+
Write-Host "`n 'SecondaryServers: ' (Get-ItemProperty -PSPath $zone.PSPath).SecondaryServers" -NoNewline
47+
Write-Host "`n 'SecureSecondaries: ' (Get-ItemProperty -PSPath $zone.PSPath).SecureSecondaries `n" -NoNewline
4548

46-
#Set-ItemProperty -PSPath $zone.PSPath -Name "SecondaryServers" -Value "" -Whatif
47-
#Set-ItemProperty -PSPath $zone.PSPath -Name "SecureSecondaries" -Value "3" -Whatif
49+
#Set-ItemProperty -PSPath $zone.PSPath -Name "SecondaryServers" -Value "" -WhatIf
50+
#Set-ItemProperty -PSPath $zone.PSPath -Name "SecureSecondaries" -Value "3" -WhatIf
4851
}
4952

5053
#Cleanup and then show the current PSSession state.
5154
if ($session) { Exit-PSSession }
5255
if ($session) { Remove-PSSession $session }
5356
Write-Host -ForegroundColor DarkYellow $session.ComputerName $session.State `n`n -NoNewline
54-
5557
}

Active Directory/Domain Services/Get-MissingADSubnets v2.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@
157157

158158
$NumberOfIPs = ([System.Math]::Pow(2, $IntIPLength)) - 1
159159

160-
$IpStart = New-IPv4NetworkAddress $ObjInputAddress $BlockBytes $IPv4Mask
160+
$IpStart = New-IPv4NetworkAddress -Address $ObjInputAddress -nbBytes $BlockBytes -IPv4Mask $IPv4Mask
161161
$Obj | Add-Member -type NoteProperty -Name Subnet -Value "$($IpStart)/$($IPv4Mask)"
162162
$Obj | Add-Member -type NoteProperty -Name IpStart -Value $IpStart
163163

164164
$ArrBytesIpStart = $IpStart.GetAddressBytes()
165165
[array]::Reverse($ArrBytesIpStart)
166-
$RangeStart = [system.bitconverter]::ToUInt32($ArrBytesIpStart, 0)
166+
$RangeStart = [System.BitConverter]::ToUInt32($ArrBytesIpStart, 0)
167167

168168
$IpEnd = $RangeStart + $NumberOfIPs
169169

170-
if (($IpEnd.Gettype()).Name -ine 'double') {
170+
if (($IpEnd.GetType()).Name -ine 'double') {
171171
$IpEnd = [Convert]::ToDouble($IpEnd)
172172
}
173173

@@ -178,7 +178,7 @@
178178

179179
$ArrBytesIpEnd = $IpEnd.GetAddressBytes()
180180
[array]::Reverse($ArrBytesIpEnd)
181-
$Obj | Add-Member -type NoteProperty -Name RangeEnd -Value ([system.bitconverter]::ToUInt32($ArrBytesIpEnd, 0))
181+
$Obj | Add-Member -type NoteProperty -Name RangeEnd -Value ([System.BitConverter]::ToUInt32($ArrBytesIpEnd, 0))
182182

183183
# return $Obj
184184
$Obj
@@ -438,7 +438,7 @@
438438
$SubnetObj = New-Object -TypeName PsObject
439439

440440
if ( $ObjIP.AddressFamily -match 'InterNetwork' ) {
441-
$SubnetObj = New-IPv4 $SubnetObj $ObjIP $IPv4Mask
441+
$SubnetObj = New-IPv4 -Obj $SubnetObj -ObjInputAddress $ObjIP -IPv4Mask $IPv4Mask
442442
$SubnetObj | Add-Member -MemberType NoteProperty -Name Computer -Value $Entry.Computer
443443
$ArrIPs += $SubnetObj
444444
} # end if $ObjIP.AddressFamily -match 'InterNetwork'
@@ -482,7 +482,7 @@
482482
$SubnetObj = New-Object -TypeName PsObject
483483
$SubnetObj | Add-Member -type NoteProperty -Name Name -Value ([string] $Subnet.Properties['cn'])
484484
$SubnetObj | Add-Member -type NoteProperty -Name Location -Value ([string] $Subnet.Properties['location'])
485-
$SubnetObj | Add-Member -type NoteProperty -Name Site -Value ([string] $RegexCN.Match( $Subnet.Properties['siteobject']).Groups[1].Value)
485+
$SubnetObj | Add-Member -type NoteProperty -Name Site -Value ([string] $RegexCN.Match( $Subnet.Properties['SiteObject']).Groups[1].Value)
486486

487487
$InputAddress = (($SubnetObj.Name).Split('/'))[0]
488488
$ADSubnetPrefix = (($SubnetObj.Name).Split('/'))[1]
@@ -492,7 +492,7 @@
492492

493493
# Check if IP is a IPv4 (IPv6 not collected)
494494
if ( $ObjInputAddress.AddressFamily -eq 'InterNetwork' ) {
495-
$SubnetObj = New-IPv4 $SubnetObj $ObjInputAddress $ADSubnetPrefix
495+
$SubnetObj = New-IPv4 -Obj $SubnetObj -ObjInputAddress $ObjInputAddress -IPv4Mask $ADSubnetPrefix
496496
$SubnetsArray += $SubnetObj
497497
} # end if $ObjInputAddress.AddressFamily -eq 'InterNetwork'
498498
} # end foreach $Subnet

0 commit comments

Comments
 (0)