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

EXE/Script Advanced PowerShell get-content problem

Votes:

0

Hi, how can I read the content of a local text file within a powershell script in a custom sensor?

I'm currently stuck while trying to read an encrypted password from local text file, specifically with the get-content command, the line is stated as follows:

$pass = get-content "C:\passlib\admpass.txt" | convertto-securestring

When the script is executed in a local powershell console works like a charm, but once it is included into the sensor the next message is displayed:

This sensor requires the PowerShell 2.0 (or higher) to be installed on the probe system. (convertto-securestring : The system cannot find the file specified. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\custsensor.ps1:8 char:59 + $admpass = get-content "C:\passlib\admpass.txt" | convertto-securestring + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], C ryptographicException + FullyQualifiedErrorId : ImportSecureString_InvalidArgument_Cryptographic Error,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand new-object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value." At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\custsensor.ps1:9 char:12 + ...

I've read in other threads that some times (don't know why) it works to set the path as follows "C$\passlib\admpass.txt", did the proper, and got the following message:

This sensor requires the PowerShell 2.0 (or higher) to be installed on the probe system. (get-content : Cannot find path 'C:\Windows\system32\C$\passlib\admpass.txt' because it does not exist. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\custsensor.ps1:8 char:12 + $pass = get-content "C$\passlib\admpass.txt" | convertto-securestring + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Windows\syst...pass.t xt:String) [Get-Content], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetCo ntentCommand new-object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value." At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\custsensor.ps1:9 char:12 + $admcred = new-object -typename System.Management.Automation.PSCredential -argum ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvoca tionException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power Shell.Commands.NewObjectCommand Invoke-Command : Cannot process argument transformation on parameter 'Credential'. Access is denied At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\custsensor.ps1:12 char:78 + ... + ~~~ + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBind ingArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Microsoft.P owerShell.Commands.InvokeCommandCommand Sending Result to output pipeline <prtg> <result> <channel>Custom Sensor Test</channel> <value></value> </result> </prtg> ) (code: PE181)

error powershell prtg

Created on Mar 23, 2017 5:29:33 PM

Last change on Mar 24, 2017 6:25:06 AM by  Stephan Linke [Paessler Support]



12 Replies

Votes:

0

Did you already try to upgrade to a newer PowerShell version as required?

Created on Mar 24, 2017 6:25:31 AM by  Stephan Linke [Paessler Support]



Votes:

0

This is what I get when I check the version, whether it be the 32 or 64 bits version:

PS C:\Users\Administrator> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      3.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.36366
BuildVersion                   6.2.9200.17065
PSCompatibleVersions           {1.0, 2.0, 3.0}
PSRemotingProtocolVersion      2.2

So I think it is above the minimum required version, is there other thing else I should check for?

Thanks in advance.

Created on Mar 24, 2017 2:55:39 PM

Last change on Mar 27, 2017 5:21:00 AM by  Sven Roggenhofer [Paessler Technical Support]



Votes:

0

Could you post the entire script please?

Created on Mar 27, 2017 6:53:44 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi, thanks for the reply, sure, here is it, please consider my comments in the first post, where I've mention that I have already tried changing the line $admpass = get-content "C:\passlib\admpass.txt" | convertto-securestring for $admpass = get-content "C$\passlib\admpass.txt" | convertto-securestring

I get different messages back, but none of them worked. Thanks in advance.

Import-Module 'C:\Program Files\Common Files\Skype for Business Server 2015\Modules\SkypeForBusiness'

$user1 = "[email protected]"
$pass1 = get-content "C:\passlib\usr4pass.txt" | convertto-securestring
$cred1 = new-object -typename System.Management.Automation.PSCredential -argumentlist $user1, $pass1

$adm = "[email protected]"
$admpass = get-content "C:\passlib\admpass.txt" | convertto-securestring
$admcred = new-object -typename System.Management.Automation.PSCredential -argumentlist $adm, $admpass

$result="<prtg>`r`n"
$testcs = Invoke-Command -ComputerName remote1.domain.com -Credential $admcred -Argumentlist $cred1 -ScriptBlock {Import-Module SkypeForBusiness; Test-CsClientAuth -TargetFqdn remote2.domain.com -UserSipAddress "sip:[email protected]" -UserCredential $args[0]}
    if ($testcs.result -eq "Failure") {
        write-host "Unable authenticate user"
    }
    else{
		$result+="  <result>`r`n"
		$result+="    <channel>Auth Test</channel>`r`n"
		$result+="    <value>"+$testcs.result+"</value>`r`n"
		$result+="  </result>`r`n"
        }
$result+="</prtg>"
Write-host "Sending Result to output pipeline"
$result

Created on Mar 27, 2017 3:06:53 PM

Last change on Mar 28, 2017 10:32:02 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hold on, is the passlib folder actually located on the probe? Or the core? Because the notifications are actually executed on and via the remote probe host, not the core server.

Created on Mar 28, 2017 11:53:17 AM by  Stephan Linke [Paessler Support]

Last change on Mar 28, 2017 11:53:25 AM by  Stephan Linke [Paessler Support]



Votes:

0

We do not have any remote probe currently, the script and passlib folder are located on the core or main probe, in fact we have only one server running PRTG where all sensors are being deployed, I've tried placing the passlib folder in the remote invoked server also, result is the same. Where should I have to place the folder? Are there any other factors I must take into consideration?

Created on Mar 28, 2017 2:38:35 PM



Votes:

0

Ah sorry, disregard that. Is it possible that the sensor is executed within a user context that has no access to the folder where the credential files are stored?

Created on Mar 29, 2017 6:47:20 AM by  Stephan Linke [Paessler Support]

Last change on Mar 29, 2017 6:47:30 AM by  Stephan Linke [Paessler Support]



Votes:

0

Can you please give me more details about the user context? Setting about the Security Context are set to Use Windows credentials of parent device, parent device's Windows credentials are from a domain user who is joined to the PRTG server's administrators group.

Created on Mar 31, 2017 6:48:52 PM



Votes:

0

Complementing last question, I've set the sensor settings with the parent device's Windows credential, which are from a domain user that is joined to the PRTG Server Administrators group, credential has the right access, but I'm still getting the same result, can you give me more detail about the user context?

Created on Apr 4, 2017 1:27:39 PM



Votes:

0

Sorry about the delay, Luis. I did some reading and you might want to try the following:

$pass = (get-content "\\<fqdn-of-your-prtg-server>\c$\passlib\admpass.txt" | convertto-securestring)

Created on Apr 4, 2017 2:17:37 PM by  Stephan Linke [Paessler Support]

Last change on Apr 4, 2017 2:17:53 PM by  Stephan Linke [Paessler Support]



Votes:

0

Thanks for replying, I'm sorry to say that it didn't work either, I've tried with the Server's IP also, the result is the same "Power Shell 2.0 or above Required" along with the aforementioned error message stating that the path couldn't be found, the part that confuses me, is why am I getting the message "PowerShell 2.0 required" if I'm sure that the version is above that? Is this a generic message? Which or where is the PowerShell executable PRTG is running to execute the script?

Thanks in advance.

Created on Apr 6, 2017 7:22:10 PM



Votes:

0

The only other way that comes to my mind would be this one:

function Passwords([ValidateSet("Get","Set")][string]$action)
   $passFile = "C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\adm.pass";
   $keyFile  = "C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\adm.key";

   if($action -eq "set"){
        $Key = New-Object Byte[] 32
        [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
        $Key | out-file $keyFile
        Read-Host "Enter Password for the $($Server) server" -AsSecureString |  ConvertFrom-SecureString -key $Key | Out-File $passFile
   }
   if($action -eq "get"){
       $Key = Get-Content $KeyFile
       $Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $servers.smtpUser, (Get-Content $passFile | ConvertTo-SecureString -Key $key)
       return $Credentials;
   }

Call the function once with Passwords -Set in order to create the password files and Passwords -Get when you need the corresponding credential object. Let me know if it worked out!

Created on Apr 10, 2017 6:31:47 AM 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.