Hello!

I have a powershell script for VMware. It counts all my snapshots.

Script:

Import-Module VMware.VimAutomation.Core >$Null

Connect-VIServer 10.20.30.40 -user vmware@test.com -password "XXXXXXXXXX" >$Null

$snapshots_count = 0
get-vm -location esx-cluster | get-snapshot | ForEach-Object {$snapshots_count ++}
 
Disconnect-VIServer -Confirm:$false


write-host "<prtg>"
write-host "<result>"
write-host "<channel>Anzahl Snapshots</channel>"
write-host "<value>$($snapshots_count)</value>"
write-host "<LimitMaxError>0</LimitMaxError>"
write-host "<LimitMode>1</LimitMode>"
write-host "</result>"
write-host "</prtg>"

When I run the script in the Powershell i get his result:

<prtg>
<result>
<channel>Anzahl Snapshots</channel>
<value>2</value>
<LimitMaxError>0</LimitMaxError>
<LimitMode>1</LimitMode>
</result>
</prtg>

But PRTG shows always 0 and not 2 (the real value).

When I change "$snapshots_count = 0" in the script PRTG will show my the chanded value. For example:

$snapshots_count = 5    -> PRGT shows 5

What I'm doing wrong?


Article Comments

This is because Connect-ViServer probably never gets executed, i.e. the variable never does change. Did you already try to set the security context of the device to the credentials of the parent object?

Additionally, where does the module reside, path-wise?


Kind regards,
Stephan Linke, Tech Support Team


Nov, 2017 - Permalink

Hi!

security context: yes, I change from "root" to the "vmware" user (as I use in the script) -> no change

What do you mean with "Additionally, where does the module reside, path-wise?" ?

I installed the VMware PowerCLI to get all the modules available in Windows Powershell.

PS: is it possiple to write here in german?


Nov, 2017 - Permalink

Hi again,

it seems like my script cannot load the vmware module

Import-Module VMware.VimAutomation.Core

when I run the script outside PRTG I works.


Nov, 2017 - Permalink

Hi,

Klar, deutsch geht auch ;) Das Modul müsste dann unter folgendem Pfad abliegen
C:\Windows\System32:\WindowsPowerShell\v1.0\Modules

Wenn dieser Modulordner in den Ordner vom Script kopiert wird, funktioniert es dann? Es muss dann entsprechend relativ geladen werden. Ansonsten müsste wahrscheinlich im PRTG Probe-Dienst ein Administrator-Account konfiguriert werden, damit das Ganze sauber funktioniert.


Mit freundlichen Grüßen,
Stephan Linke, Tech Support Team


Nov, 2017 - Permalink

Hi!

Ich habe das Modul nach "C:\Windows\System32\WindowsPowerShell\v1.0\Modules" und "C:\Windows\SysWow64\WindowsPowerShell\v1.0\Modules" kopiert. Jetzt funktiert der Sensor wie gewollt.

Vielen Dank!!!


Nov, 2017 - Permalink

Sehr gut! Schönes Wochenende! ;)


Mit freundlichen Grüßen,
Stephan Linke, Tech Support Team


Nov, 2017 - Permalink