Last active
August 29, 2015 14:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
---------------------------------------------------------------------------------- | |
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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was written with various information from Google searches, but mainly stackoverflow and the Hey, Scripting Guy! Blog.