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." }
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
Jul, 2020 - Permalink