Skip to content

Instantly share code, notes, and snippets.

@iamgabeortiz
Last active August 29, 2015 14:01
Show Gist options
  • Save iamgabeortiz/dd60cb6edb133ed30d65 to your computer and use it in GitHub Desktop.
Save iamgabeortiz/dd60cb6edb133ed30d65 to your computer and use it in GitHub Desktop.
A little PowerShell script to grab the backup status from multiple servers and outputs them to a log file.
<#
----------------------------------------------------------------------------------
Caveats
-Assumes you have Windows Server Backup Command Line components already installed
on the server you are connecting to.
#>
# Start logging
If ($Host.Name -ne "Windows PowerShell ISE Host") {
$timestamp = Get-Date -Format yyyyMMddHHmmmss
$filepath = "absolute_path_to_file\PowerShell_transcript."+$timestamp+".txt"
Start-Transcript -Path $filepath -Verbose -NoClobber
}
# Store user credentials for resuse
$cred = Get-Credential -Credential domain\user_name
# Instnatiate session variables
$sess1 = New-PSSession -ComputerName computer_name -Credential $cred
$sess2 = New-PSSession -ComputerName computer_name -Credential $cred
$sess3 = New-PSSession -ComputerName computer_name -Credential $cred
# Connect to server1 and get backup status
Invoke-Command -Session $sess1 -ScriptBlock {Add-PSSnapin windows.serverbackup}
Invoke-Command -Session $sess1 -ScriptBlock {Get-WBSummary}
# Connect to server2 and get backup status
Invoke-Command -Session $sess2 -ScriptBlock {Add-PSSnapin windows.serverbackup}
Invoke-Command -Session $sess2 -ScriptBlock {Get-WBSummary}
# Remove sessions
Get-PSSession | Remove-PSSession
# End logging
If ($Host.Name -ne "Windows PowerShell ISE Host") {Stop-Transcript}
@iamgabeortiz
Copy link
Author

This was written with various information from Google searches, but mainly stackoverflow and the Hey, Scripting Guy! Blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment