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

Using net use in EXE/Script Sensor

Votes:

0

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

driveletters error exe-script-sensor

Created on Jun 14, 2016 8:41:57 AM

Last change on Jun 15, 2016 12:27:17 PM by  Stephan Linke [Paessler Support]



3 Replies

Votes:

0

Why not use the UNC path directly? Network shares are always a bit problematic in PRTG, when they're mapped as drives :)

Created on Jun 14, 2016 10:45:40 AM by  Stephan Linke [Paessler Support]



Votes:

0

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

Created on Jun 15, 2016 11:48:47 AM



Votes:

0

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

Created on Jun 15, 2016 12:33:08 PM by  Stephan Linke [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.