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)
Add comment