Here’s a PowerShell script that can be used to scan for Windows updates, install them and optionally restart the system automatically. I’ve been using this for a few years now on Windows Server 2008 R2 and above without issues.
Continue readingTag: PowerShell
For a time, I had a server with an issue where the IIS SMTP virtual server stopped due to an error. My usual automatic checks for stopped Windows services didn’t pick this up because the Windows service continued to run, even though the SMTP virtual server had stopped.
This caused some internal emails to be delayed. It was easy enough to start the virtual server again, but better to put a script in place to check the status and start the SMTP virtual server if necessary.
Continue readingHere’s a PowerShell script for a function to send email with optional attachments. It accepts a comma-separated list of attachments, or no attachments at all.
You can include this in other PowerShell scripts to make this function available, rather than having the email sending functionality repeated in multiple scripts.
Continue readingHere’s a quick one-liner that can rename multiple files with PowerShell. The rename-item cmdlet can be used to search and replace text in the original filename.
dir "c:\Work" -s | rename-item -NewName {$_.name -replace "text-to-find","repacement-text"}
Continue reading
Here’s a quick PowerShell script which allows you to set the computer description remotely.
You’ll need to run this in a PowerShell window with administrative rights for the remote PC.
$RemotePC = Read-Host -Prompt 'Input the remote computer name e.g. PC0123'
$RemoteDescription = Read-Host -Prompt 'Input the new description for the remote computer'
$PC = Get-WmiObject -class Win32_OperatingSystem -computername $RemotePC
$PC.Description = $RemoteDescription
$PC.Put()