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." }
Add comment