PoshCode Archive  Artifact [9ee77bd486]

Artifact 9ee77bd486c7a52b25c9931ae55695bbb7529d0c02e0c363cfe64bbb0a1fd830:

  • File Check-Backups.ps1 — part of check-in [a2ce507b68] at 2018-06-10 14:21:54 on branch trunk — Check for successful backups in NetWorker (user: gonads99 size: 1749)

# encoding: ascii
# api: powershell
# title: Check Backups
# description: Check for successful backups in NetWorker
# version: 0.1
# type: script
# author: gonads99
# license: CC0
# x-poshcode-id: 6852
# x-archived: 2017-04-27T07:10:09
# x-published: 2017-04-21T04:50:00
#
#
# lists
$devList = New-Object System.Collections.ArrayList
$prodList = New-Object System.Collections.ArrayList

Try {
    $hostList = gc $hostsToCheckFile -ErrorAction Stop
}
Catch {
    #$ErrorMessage = $_.Exception.Message
    #$FailedItem = $_.Exception.ItemName
    echo "ERROR: Could not open $hostsToCheckFile..."
    Break
}
    

foreach ($line in $hostList) {
    #echo "$line"

    if ($line -match "^nzp") {
        echo "Adding $line to prod list..."
        $prodList.Add($line)
    }
    elseif ($line -match "^nz") {
        echo "Adding $line to dev list..."
        $devList.Add($line)
    }
    else {
        echo "Cannot process $line..."
    }
}

# create a new remote session on the NSR server
$s = New-PSSession -ComputerName $devServer #-Credential $devCreds

# $devList array needs to be wrapped in an array as ArgumentList expects an array of arguments. See http://stackoverflow.com/questions/17577705/passing-array-to-another-script-with-invoke-command.
Invoke-Command -Session $s -ArgumentList (,$devList) -ScriptBlock {
    param($devList)

    #$devList

    foreach ($client in $devList) {
        echo "Checking client $client..."
        $out = (mminfo -q "savetime>=24 hours ago,name=/,client=$client" -ot -r "savetime,client,name,sumsize,level")
        echo $out
    }
}


# There's a limit of 5 remote PS sessions per user
echo "Removing PS session..."
Remove-PSSession $s