Powershellscripts für Solarwinds N-Central


Die bereits sehr Umfangreiche IT-Monitoring und Management Software N-Central lässt sich mit Powershellscripts noch erweitern. Einige Funktionen haben uns gefehlt. So gibt es z.B. keinen Monitor für die Schattenkopien oder den Profilspeicherplatz (ProQuota). Ich habe mich daran gesetzt und das selbst gebastelt. Hier findet ihr das Ergebnis von dieser Arbeit als Script oder fertiges .XML zum import in N-Central

ProQuota

######################################################
# Author: Marco Immervoll and Markus Rockenbauer #
# Input: #
# Output: Profilesize in % #
# Profilesize in KB #
# Max Profilesize from Grouppolicy #
# List of Exclusions #
# List of 20 biggest files #
######################################################

#find userid
$username= Get-WMIObject -class Win32_ComputerSystem
$username = $username.username.split("")

$filter = "name='" + $username[1] + "' AND domain='" + $username[0] + "'"
$a = Get-WmiObject win32_useraccount -Filter $filter

#read exclusion paths and the max profile size value
$b = "REGISTRY::HKEY_USERS" + $a.sid + "softwarepoliciesmicrosoftwindowssystem"
$excludes = get-itemproperty $b
$b = "REGISTRY::HKEY_USERS" + $a.sid + "softwaremicrosoftwindowscurrentversionpoliciessystem"
$maxmb = get-itemproperty $b

#makes old win XP exclusions invalid
$filter = "sid='" + $a.sid + "'"
$folder = Get-WMIObject win32_UserProfile -Filter $filter
$excludefolder = $folder.localpath+""+$excludes.excludeprofiledirs.replace(";",","+$folder.localpath+"")
$excludefolder = $excludefolder + "," + $folder.localpath + "AppDatalocal" + "," + $folder.localpath + "AppDatalocallow"
#-------!!!! you may have to change "Anwendungsdaten" if you use another language then german
$excludefolders = $excludefolder.replace("Anwendungsdaten","dump").split(",")

#Measure the size of all excluded folders

$allexcl = Get-Childitem -path $excludefolders -force -recurse -ErrorAction SilentlyContinue | Sort-Object -Property length,fullname -descending
$sizeexcludes = ($allexcl | Measure-Object -property length -sum).sum

#Measure the size of all folders
$all = Get-Childitem -path $folder.localpath -force -recurse -ErrorAction SilentlyContinue | Sort-Object -Property length,fullname -descending
$sizetotal = ($all | Measure-Object -property length -sum ).sum

#findes the biggest 20
$j=0
$biggest = ""
for($i=0;$i -le 999999; $i++)
{

if ($all[$i].fullname -contains $allexcl[$i-$j].fullname)
{
}
else
{
$biggest += " "+ $all[$i].length + "--" + $all[$i].fullname + "`n"
$j++
}
if($j -ge 20) {break}
}

#calculates profilesize
$trueprofilesize= ($sizetotal - $sizeexcludes) /(1024)
$percent = $trueprofilesize / $maxmb.maxprofilesize

#Output
$percent*100
$trueprofilesize
$maxmb.maxprofilesize
$excludefolder.replace(","," ")
$biggest

Shadowcopys

######################################################
# Author: Marco Immervoll 2016 #
# Input: Driveletter --> $letter #
# Output: #
# Date of Oldest and Latest VSS #
# Total Amount of Shadowcopys #
# Age in hours of Oldest and Latest VSS #
######################################################

##########Input############
$letter="c:"

##########script###########
$date= Get-Date
$wmi = Get-WmiObject -Class Win32_OperatingSystem

#reads deviceID of $letter and converts the Object into a simple string
$device1 = Get-WmiObject win32_volume -filter "DriveLetter='$letter'" | select DeviceID | out-string
$device2 = $device1.replace("DeviceID",$null).replace("--------",$null).trim()

#reads the count of all shadowcopys for $device2
$sc_count_raw = Get-WmiObject -Class win32_shadowcopy | where {$_.Volumename -eq $device2} | measure Count -sum
$sc_count = $sc_count_raw.sum

#Reads date and time of oldest VSS
$sc_oldest_raw = Get-WmiObject -Class win32_shadowcopy | where {$_.Volumename -eq $device2} |sort installdate |select -first 1 |select installdate | out-string
$sc_oldest = $sc_oldest_raw.replace("installdate",$null).replace("-----------",$null).trim()
$sc_oldest1 = $wmi.ConvertToDateTime($sc_oldest)
$ageOld=NEW-TIMESPAN –Start $sc_oldest1 –End $date

#Reads date and time of latest VSS
$sc_last_raw = Get-WmiObject -Class win32_shadowcopy | where {$_.Volumename -eq $device2} |sort installdate |select -last 1 |select installdate | out-string
$sc_last = $sc_last_raw.replace("installdate",$null).replace("-----------",$null).trim()
#wandelt datum in lesbares format um
$sc_last1 = $wmi.ConvertToDateTime($sc_last)
$ageLast=NEW-TIMESPAN –Start $sc_last1 –End $date

#############Output############
" VSS for $Letter"
" Oldest VSS: $sc_oldest1"
" Age in hours: $ageOld.totalhours"
" latest VSS: $sc_latest1"
" Age in hours: $agelast.totalhours"
" Total Amount of VSS: $sc_count"

Hinterlasse einen Kommentar