What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Wrong values from Powershell Script

Votes:

0

Your Vote:

Up

Down

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 [email protected] -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?

powershell snapshot vmware

Created on Nov 23, 2017 12:00:53 PM by  D4v3R0 (0) 1

Last change on Nov 23, 2017 2:32:01 PM by  Stephan Linke [Paessler Support]



6 Replies

Votes:

0

Your Vote:

Up

Down

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

Created on Nov 23, 2017 2:34:00 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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?

Created on Nov 23, 2017 2:49:04 PM by  D4v3R0 (0) 1



Votes:

0

Your Vote:

Up

Down

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.

Created on Nov 24, 2017 7:05:05 AM by  D4v3R0 (0) 1



Votes:

0

Your Vote:

Up

Down

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

Created on Nov 24, 2017 7:13:26 AM by  Stephan Linke [Paessler Support]

Last change on Nov 24, 2017 7:13:32 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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!!!

Created on Nov 24, 2017 9:42:53 AM by  D4v3R0 (0) 1



Votes:

0

Your Vote:

Up

Down

Sehr gut! Schönes Wochenende! ;)


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

Created on Nov 24, 2017 10:00:28 AM by  Stephan Linke [Paessler Support]

Last change on Nov 24, 2017 10:00:35 AM by  Stephan Linke [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.