PowerShell in a NutShell

I've seen so many people wonder what exactly PowerShell is and how they can help themselves when writing scripted solutions to automate day to day, as well as excruciating one off tasks. So what is PowerShell? It's an engineering and administration tool to be used by anyone in Information Technology to improve productivity and reduce human error. See the attached resource for help on scripting PowerShell. Also, MVA offers an indepth course explaining the basics here: https://mva.microsoft.com/en-US/training-courses/getting-started-with-powershell-30-jump-start-8276?l=r54IrOWy_2304984382

I've used it personally to script out domain related software updates and saved countless hours doing so. I have an example I wrote out in order to update server monitoring agents on a domain network. This script was used to update opsview agents within just a few minutes on over 100 servers as well as backup existing configs. This first script backs up everything to the same directory it's located in.

$serverList = Get-ADComputer -Filter {name -like "ServerNameConvention*"}
foreach ($serverName in $serverList) {
$ErrorActionPreference = "Stop" try { $server = $serverName.Name Write-Host $server Copy-Item "\$server\c$\PROGRA~1\opsview\NSClient++\opsview.ini" "\$server\c$\PROGRA~1\opsview\NSClient++\opsview-orginal.ini" -recurse -force Copy-Item "\$server\c$\PROGRA~1\opsview\NSClient++\scripts*" "\$server\c$\PROGRA~1\opsview\NSClient++\scripts-original" -recurse -force Start-Sleep -s 5 } catch { $error >> C:\Users\username\Desktop\file.txt } }

This second one deploys the files from the network share located on the server.

$computers = gc "C:\Scripts\ServerList.txt"
$source = "\ServerShareName\OpsView\opsview.ini" $dest = "\c$\PROGRA~1\opsview\NSClient++\" foreach ($computer in $computers) {
if (test-Connection -Cn $computer -quiet) { Copy-Item $source -Destination \$computer\$dest -Force Get-Service -Name NSClientpp -ComputerName $computers | Restart-service } else { "$computer is not online" } }

Just for kicks, here's a quick Email to SMS script utilizing SMTP.

$properties = @{
to = '#@vtext.com' from = 'example@gmail.com' body = "Hello World." subject = "Alert" smtpserver = 'SMTP Server IP or DNS Name'} Send-MailMessage @properties