- List all servers (better FQDN or IP) in a txt file name "servers.txt".
- Keep the PowerShell script (say script.ps1) at the same location as the text file.
August 29, 2022
Run PowerShell script to multiple servers remotely
August 17, 2022
Get the list of all Hotfix in multiple servers for specific time period
- Create a text file (.txt) with the name "serverlist.txt" and mention all server's FQDN.
- In this example, we will get the hotfix details from 1st August to 30th August 2022.
- Note: The date in this script will be MM/DD/YYYY
Where {
$_.InstalledOn -gt "8/1/2022" -AND $_.InstalledOn -lt "8/30/2022" } | Select-Object pscomputername,description,hotfixid,installedby,installedon |
Export-Csv August_Patch.csv
August 11, 2022
How to Backup all Microsoft DNS Zones
# Get the name of the server with the env variable
$DNSServer=get-content env:computername
# Define folder where to store DNS backup
$BackupFolder="C:\Windows\System32\DNS\Backup"
# Define file name where to store DNS settings
$DNSFile=Join-Path $BackupFolder "input.csv"
# Check if the folder already exists. If exists, delete all content
if (-not(test-path $BackupFolder)) {
new-item $BackupFolder -Type Directory | Out-Null
} else {
Remove-Item $BackupFolder"\*" -recurse
}
# Get DNS settings using WMI Object
$List = get-WMIObject -ComputerName $DNSServer -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone
# Export information into input.csv file
$List | Select Name,ZoneType,AllowUpdate,@{Name="MasterServers";Expression={$_.MasterServers}},DsIntegrated | Export-csv $DNSFile -NoTypeInformation
# Call Dnscmd.exe to export DNS zones
$list | foreach {
$path="backup\"+$_.name
$cmd="dnscmd {0} /ZoneExport {1} {2}" -f $DNSServer,$_.Name,$path
Invoke-Expression $cmd
}
#End of script
$DNSServer=get-content env:computername
# Define folder where to store DNS backup
$BackupFolder="C:\Windows\System32\DNS\Backup"
# Define file name where to store DNS settings
$DNSFile=Join-Path $BackupFolder "input.csv"
# Check if the folder already exists. If exists, delete all content
if (-not(test-path $BackupFolder)) {
new-item $BackupFolder -Type Directory | Out-Null
} else {
Remove-Item $BackupFolder"\*" -recurse
}
# Get DNS settings using WMI Object
$List = get-WMIObject -ComputerName $DNSServer -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone
# Export information into input.csv file
$List | Select Name,ZoneType,AllowUpdate,@{Name="MasterServers";Expression={$_.MasterServers}},DsIntegrated | Export-csv $DNSFile -NoTypeInformation
# Call Dnscmd.exe to export DNS zones
$list | foreach {
$path="backup\"+$_.name
$cmd="dnscmd {0} /ZoneExport {1} {2}" -f $DNSServer,$_.Name,$path
Invoke-Expression $cmd
}
#End of script
Subscribe to:
Posts (Atom)