Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Skript Fehler.....

$
0
0

Hallo,

ich habe folgendes Script:

#
# PowerCLI script for monitoring old VM snaphots in a datacenter.
# Author: Haukur Kristinsson
#
# Example commandline in nsc.ini (for NRPE++):
# command[check_REYDatacenterSnaphots]=C:\Users\haukurk>powershell -PSConsoleFile "c:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "& 'c:\ReportsCLI\REYSnapshotNagios.ps1'"
# Where check_REYDatacenterSnaphots is the command, vim.psc1 the console file, and REYSnapshotNagios.ps1 this script.
#
# This is nothing fancy, but I decided to share it with you..
#

$server = "VMCBDF01" #vCenter server..
$user = "xxxx\User" # user
$pass = "xxxxxx" # pass

$datacenter = "Datacenter" # datacenter name
$criticalSnaphostDays = -1 # how many days can a snapshot last?

Connect-VIServer -Server $server -Protocol https -User $user -Password $pass

#Start with 0 snapshots :-)
$oldSnapshots = 0

# Fetch snapshots from the datacenter.
Get-View -ViewType VirtualMachine -Property Name,Snapshot -SearchRoot(Get-Datacenter $datacenter | get-view).MoRef `
-Filter @{"Snapshot"="VMware.Vim.VirtualMachineSnapshotInfo"} | foreach-object {
    $vmname = $_.Name
    (Get-View -Id $_.MoRef -Property Snapshot).Snapshot.RootSnapshotList | foreach-object {
        If ($_.CreateTime -lt (get-date).adddays($criticalSnaphostDays))
        {
		# Lets increment the integer.
		$oldSnapshots++
        }
    }
}

# Return Values for NRPE: 
# - OK (0)  
$exitOK = 0
# - WARNING (1) 
$exitWarn = 1
# - Critial (2)
$exitCritical = 2 
# - UNKNOWN (3)
$exitUnknown = 3

# Exit with approriate exit code.
if ($oldSnapshots -eq 0) {
	Write-Host "OK - $oldSnapshots snapshots older than $criticalSnaphostDays"
	exit $exitOK 
}
if ($oldSnapshots -eq 1) {
	Write-Host "WARNING - $oldSnapshots snapshots older than $criticalSnaphostDays"
	exit $exitCritical 
}

# Something went wrong...
Write-Host "UNKNOWN script state"
exit $returnStateUnknown

Es kommt die Meldung Unknown script state…...
Finde den Fehler leider nicht......
Jemand eine Idee warum er mir das auswirft?

Danke und Gruß
Dennis



Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>