What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell script in PRTG

Votes:

0

Hi All,

I try to use powershell to get some extended properties of all the files in my folder. I use the script below and from the powershell console it works fine. When PRTG runs it, it gives the error below:

You cannot call a method on a null-valued expression.
At C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\GetMovieTitles_GET.ps1:2 char:1
+ $com.Items() | ForEach-Object {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Below is the script im using:

$com = (New-Object -ComObject Shell.Application).NameSpace('\\my.machine\drive\folder\')
$com.Items() | ForEach-Object {
        New-Object -TypeName PSCustomObject -Property @{
            Name = $com.GetDetailsOf($_,0)
            Size = $com.GetDetailsOf($_,1)
            ItemType = $com.GetDetailsOf($_,2)
            Title = $com.GetDetailsOf($_,21)
            }
        } | Select-Object -Property Title, Name | Where-Object -Property Title -GT $false | Format-Table -HideTableHeaders -OutVariable get | Out-File -FilePath C:\Log\myoutfile.log

If ($get.Count -LE 0) {
                      Write-Host "0:Status OK - Everything is fine, nothing to see here."
                      }
If ($get.Count -GE 1) {
                      Write-Host "2:Status ERROR - Title(s) incorrect! Look in folder `"\\my.machine\C:\Log\myoutfile.log`" for the file(s) that have a title set."
                      }

null-valued powershell prtg regular-expression

Created on Jul 4, 2020 3:38:09 PM

Last change on Jul 6, 2020 4:50:02 AM by  Sven Roggenhofer [Paessler Technical Support]



1 Reply

Votes:

0

Hello,

Thank you for your post.

Please go to the "Settings" tab of the sensor and select the option "Use Windows credentials of parent device" (per default the sensor uses the security context of the probe service which runs under the "Local System" account). Afterwards, go into the "Settings" tab of the parent device of the sensor and under "Credentials for Windows" enter the credentials of the user you used to run the script manually.

Which Powershell console did you use to check the script? The probe is a 32-bit process so it uses the 32-bit version of powershell. In case you have tried the script in the 64-bit powershell, please try it again in the 32-bit version and check if it works.


Kind regards,
Sasa Ignjatovic, Tech Support Team

Created on Jul 6, 2020 8:16:44 AM by  Sasa Ignjatovic [Paessler Support]




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.