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:

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

PowerShell – Out-Notepad function

There are many out-notepad functions out there but for some reason I found them either too long or too complicated so here is mine, short and sweet:

Function Out-Notepad {
$fso=new-object -com scripting.filesystemobject
$tempfile=Join-Path $env:temp $filename
$strText | Out-File $tempfile
notepad $tempfile
#tidy up
sleep 3
if (Test-Path $tempfile) {del $tempfile}

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 – Graphical Tools Cmdlets

Out-GridView gives a dynamic table view of results in a pipeline with sorting and filtering capabilities and when used with -PassThru can be used interactively within a pipeline to select objects to send back to the pipeline.

PS c:\>Get-ADComputer -Filter * | out-gridview -PassThru | select name,enabled
name enabled
---- -------
PC1 False
PC2 True
PC3 True

Show-Command gives a graphical view of a command including parameter sets, parameters, switches, etc…

Get-Help -ShowWindow works again to give a graphical view of PowerShell help content.

Remote Desktop/Terminal Server – Installing/removing software

Correct procedure to install software on Terminal Server:
Open cmd (as addministrator) and type in:

change user /install   [enter]
User session is ready to install applications.

Now add or remove the programs that you want.
when done:

change user /execute    [enter]
User session is ready to execute applications.