cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 10

Powershell Monitor / Basic Authentications / Credentials

Jump to solution

Hello Thwack-Folks!

Brief situation:

I do have a powershell monitor, which opens a website and parses the content. For access I do have to pass a basic http authentication.

Script is ready, tested and works, now I am curious about the credentials. When setting up an orion powershell monitor you are able to select credentials for your access.

So what I am looking for is, instead of using this line and storing username and password in plain inside the script

$webclient.credentials = new-object system.net.networkcredential("yourusername", "yourpassword")


I would like to use the credentials stored in orion.

So my question is, is it possible and if yes, how to I transfer the credentials from orion to the script monitor?


Thank you in advance!

-FRA

1 Solution

Instead of a script have you considered using the HTTP User Experience Monitor instead?

View solution in original post

0 Kudos
11 Replies
Level 12

Hello,

For PowerShell Script Monitor you can use following approach to get user name and password. For some security reasons the ${USER} and ${PASSWORD} variables are not available for PowerShell Script Monitor.

Function SecureStringToString($value)
{
    [System.IntPtr] $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($value);
    try
    {
        [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr);
    }
    finally
    {
        [System.Runtime.InteropServices.Marshal]::FreeBSTR($bstr);
    }
}

$c = Get-Credential -credential ${CREDENTIAL}
[string] $username = $c.Username
[string] $password = SecureStringToString $c.Password

Thank you,

Lukas Belza (SolarWinds development)

Good Morning Lukas!

Thank you for your hint.

The variable ${CREDENTIALS} was not listet under ScriptMacros.

So I used your script part you posted and it works fine.

Thanks again

-FRA

0 Kudos

Hi,

i am trying to test basic http authentication but i don't familiar with PowerShell,

can you publish your template so i can  use it ?

Regards

Rafi

0 Kudos

Good afternoon Rafish!

Sure. This script uses the credentials provided inside the orion credential library

and outputs the figure of a website

Function SecureStringToString($value)

{

    [System.IntPtr] $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($value);

    try

    {

        [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr);

    }

    finally

    {

        [System.Runtime.InteropServices.Marshal]::FreeBSTR($bstr);

    }

}

$c = Get-Credential -credential ${CREDENTIAL}

[string] $username = $c.Username

[string] $password = SecureStringToString $c.Password

After this, you are able to use the variables freely

For example

$webclient = new-object system.net.webclient

$webclient.credentials = new-object system.net.networkcredential($username, $password)

0 Kudos

Thank you frama! This was exactly what I needed to pass a cred into my script as a string.

0 Kudos

Hi Frama,

Thank you very much for your quick response.

I don't really know what to do with the script, i will explane my needs.

I want to check a web site the problem is that web site is protect with basic http authentication, so what need is that the solarwinds template in sam will give the  basic http authentication the credential and check the open page ( like in http from login ).

In the script you send to me i dont understand where i should write the Url and where is the credential name is.

Regards

Rafi

0 Kudos

Instead of a script have you considered using the HTTP User Experience Monitor instead?

View solution in original post

0 Kudos

Hi,

I cant because i have to do login, the website is protected with "basic http authentication"  so the first thing i see on my screen is the popup window of the basic http authentication,

Only after i provide the right credential i can see the web site, and this is what i want from the script.

In the solarwinds template they have something like this the template name is " Http From Login" but this only for new web site with login options like chat sites.

0 Kudos

SAM's HTTP User Experience Monitor  supports both Basic and NTLM website authentication.

Hi,

Thanks works good, it was easier then i thought.

Regards

Rafi 

0 Kudos
Product Manager
Product Manager

Have you looked through the list of Script Macros? I believe you're looking for the ${USER} and ${PASSWORD} variables.

0 Kudos