PowerShell – get windows 10 versions

Below script lists all Windows 10 versions that are installed on computers in Active Directory:

$win10 = get-adcomputer -filter 'OperatingSystem -like "Windows 10*"' -prop *
$win10count = ($win10 | Sort OperatingSystemVersion).count
$subject = "All Win 10 systems $win10count"
$win10_versions = $win10 | Sort OperatingSystemVersion | Select OperatingSystemVersion -unique

$result = @()
foreach ($ver in $win10_versions) {

$version = $ver.OperatingSystemVersion
$count = ($win10 | where OperatingSystemVersion -like $ver.OperatingSystemVersion | select OperatingSystemVersion | measure ).count
$result += New-Object psobject -Property @{
Win10_version = $version
Count = $Count
}
}

Send-MailMessage -From email@address.com -To email@address.com -subject $Subject -Body ($result | out-string) -smtpServer MAIL_SERVER -port 25

Example output:
.\get-Windows10_versions.ps1

Win10_version Count
------------- -----
10.0 (10240)      1
10.0 (10586)      9
10.0 (14393)     14
10.0 (15063)      4
10.0 (16299)     23
10.0 (17134)     18
10.0 (17763)     21
10.0 (18362)     35
10.0 (18363)    140
10.0 (19041)      1

Microsoft DNS server – backup and restore AD integrated zone

1. Backup the existing zone to a zone file. Resulting file will always be placed in C:\Windows\system32\dns – this can’t be controlled:
dnscmd /zoneexport zone.local zone-backup-file.zone

2. To restore the zone, move the zone-backup-file.zone file back into C:\Windows\system32\dns then:
dnscmd /zoneadd zone.local /primary /file zone-backup-file.zone /load

And finally, convert it into an AD integrated zone:
dnscmd /zoneresettype zone.local /dsprimary

Powershell – Exchange – enable/disable junk mail rule in a mailbox

Set-MailboxJunkEmailConfiguration -Enabled <$true | $false>

To check:

Get-MailboxJunkEmailConfiguration

To disable the junk email rule on all mailboxes in Exchange:

$All = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$All | foreach {
Set-MailboxJunkEmailConfiguration $_.Name -Enabled $false
}

Powershell – DNS lookup

param (
[Parameter(Mandatory=$true)]
[string]$HostName
)
$output = $null
$output = @()
$DNSServers = Get-ADDomainController -Filter *
$DNSServers | foreach {
$query = Resolve-DnsName -Name $hostname -Server $_.HostName
$result = New-Object psobject -Property @{
dnsserver = $_.Name
hostname = $query.name
IPAddress = $query.ipaddress
}
$output += $result
}
$output | select hostname,ipaddress,dnsserver | sort ipaddress

save it as for example: dns-lookup.ps1 then

PS C:\Scripts> .\dns-lookup.ps1 server2016
hostname IPAddress dnsserver
-------- --------- ---------
server2016.domain.local 192.168.1.53 DC_01
server2016.domain.local 192.168.1.53 DC_02
server2016.domain.local 192.168.1.53 DC_09