We have EXE/script sensor defined running script below.
net use s: /delete net use s: \\10.10.0.43\MyLibrary\Zalohy\Miranda /user:jmeno heslo /PERSISTENT:NO $result = Get-ChildItem s:\|where{$_.LastWriteTime -gt (get-date).AddDays(-2)} $result = @($result).Count; if($result -eq 2) { write-host -f green 1:OK } else { if ($result -gt 0){ write-host -f yellow 2:WARNING } else {write-host -red 0:ERROR} }
After running this script in command line on Win-machine is everything OK.... But running the same in sensor ends with this error message:
System Error: Cannot find drive. A drive with the name 's' does not exist. At D:\RPTG\custom sensors\EXE\Miranda.ps1:5 char:24 + $result = Get-ChildItem <<<< s:\|where{$_.LastWriteTime -gt (get-date).AddDa ys(-2)} + CategoryInfo : ObjectNotFound: (s: (code: PE022)
It seems like problem using net use command...
Thank you in advance, Jan
Article Comments
Unfortunately, probe calling the script is being installed on Windows machine and our drive is remote drive on NAS. Windows machine is using this NAS for backup. This NAS is shared over SMB and process of backup is running during power-shell script also using net use. It works properly....
Jun, 2016 - Permalink
Hm, could you try using New-PSDrive?
$username = "jmeno" $password = "heslo" # Generate credentials object for authentication $SecPasswd = ConvertTo-SecureString $password -AsPlainText -Force $Credentials = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) New-PSDrive –Name "S" –PSProvider FileSystem –Root "\\10.10.0.43\MyLibrary\Zalohy\Miranda" -Credential $Credentials
Jun, 2016 - Permalink
Why not use the UNC path directly? Network shares are always a bit problematic in PRTG, when they're mapped as drives :)
Jun, 2016 - Permalink