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

Run Powershell script remotely but not Exchange server

Votes:

0

Hello

It seems complicated to find how to create a PSSession to a remote server which is not an Exchange server.

This works only for an Exchange server:

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://[exchangeServer]/powershell/" -Authentication Kerberos
Import-PSSession $session -DisableNameChecking

I usually create sessions to our servers with

$scriptBlock{
"test" > "C:\temp\test.txt"
}

$session = New-PSSession -computerName $computername -Authentication Kerberos 
Invoke-Command -computerName $computername -scriptBlock $scriptBlock

But the code above does not work with PRTG. I receive an error code: PE231 and code: PE233!

Please help us to find a way to create a remote session with powershell to a server which is not an Exchange server.

powershell pssession remote

Created on Jun 1, 2016 8:08:50 AM

Last change on Jun 1, 2016 12:00:26 PM by  Torsten Lindner [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

Hi Thanks for your reply. Acutally I just got it working. Sorry I'm noob with PRTG.

My code:

$computerName = "serverName" # for me it does not work with IP

$session = New-PSSession -computerName $computername -Authentication Kerberos #-credential $credential 

$scriptBlock = {
    import-module failoverclusters
    
    $clusterRessources = Get-ClusterResource

    $result= "<?xml version=`"1.0`" encoding=`"Windows-1252`" ?>`r`n"
    $result+="<prtg>`r`n"

    $clusterRessources | % {
        $name = $_.name
        $state = $_.state
        if($state -eq "Online"){$state = 1} else{$state = 0}

        $result+="   <result>`r`n"   
        $result+="       <channel>$name</channel>`r`n"
        $result+="       <value>$state</value>`r`n"
        $result+="   </result>`r`n"
    }

    $result+="<text>OK</text>`r`n"
    $result+="</prtg>`r`n"
    $result
}

Invoke-Command -computerName $computername -scriptBlock $scriptBlock
Remove-PSSession -computerName $computername
Exit 0

and the output

<prtg>
   <result>
        <channel>Cluster IP Address</channel>
       <value>1</value>
   </result>
   <result>
        <channel>Cluster Name</channel>
       <value>1</value>
   </result>
   <result>
        <channel>IP Address 172.22.22.74</channel>
       <value>1</value>
   </result>
   <result>
        <channel>Quorum Broker RDS</channel>
       <value>1</value>
   </result>
   <result>
        <channel>RDSTEMP</channel>
       <value>1</value>
   </result>
   <result>
        <channel>Remote Desktop Connection Broker</channel>
       <value>1</value>
   </result>
   <text>OK</text>
</prtg>

Created on Jun 2, 2016 2:58:41 PM



5 Replies

Votes:

0

Hi Yann,

We will require the results of this custom script. Therefore, kindly enable the "Write EXE result to disk" option in the settings of the "exe / Script Sensor and post the results. You can also create a command in your script to write the results in a text file.

Best regards, Felix

Created on Jun 2, 2016 1:21:07 PM by  Felix Saure [Paessler Support]



Accepted Answer

Votes:

0

Hi Thanks for your reply. Acutally I just got it working. Sorry I'm noob with PRTG.

My code:

$computerName = "serverName" # for me it does not work with IP

$session = New-PSSession -computerName $computername -Authentication Kerberos #-credential $credential 

$scriptBlock = {
    import-module failoverclusters
    
    $clusterRessources = Get-ClusterResource

    $result= "<?xml version=`"1.0`" encoding=`"Windows-1252`" ?>`r`n"
    $result+="<prtg>`r`n"

    $clusterRessources | % {
        $name = $_.name
        $state = $_.state
        if($state -eq "Online"){$state = 1} else{$state = 0}

        $result+="   <result>`r`n"   
        $result+="       <channel>$name</channel>`r`n"
        $result+="       <value>$state</value>`r`n"
        $result+="   </result>`r`n"
    }

    $result+="<text>OK</text>`r`n"
    $result+="</prtg>`r`n"
    $result
}

Invoke-Command -computerName $computername -scriptBlock $scriptBlock
Remove-PSSession -computerName $computername
Exit 0

and the output

<prtg>
   <result>
        <channel>Cluster IP Address</channel>
       <value>1</value>
   </result>
   <result>
        <channel>Cluster Name</channel>
       <value>1</value>
   </result>
   <result>
        <channel>IP Address 172.22.22.74</channel>
       <value>1</value>
   </result>
   <result>
        <channel>Quorum Broker RDS</channel>
       <value>1</value>
   </result>
   <result>
        <channel>RDSTEMP</channel>
       <value>1</value>
   </result>
   <result>
        <channel>Remote Desktop Connection Broker</channel>
       <value>1</value>
   </result>
   <text>OK</text>
</prtg>

Created on Jun 2, 2016 2:58:41 PM



Votes:

0

Thanks for sharing, so everything is up and running correctly?

Created on Jun 3, 2016 3:35:11 PM by  Felix Saure [Paessler Support]



Votes:

0

For reference, there are a few tips and tricks here https://thedomainiown.wordpress.com/prtg-related/general-custom-exe-script/ (see the remoting section)

Created on Jun 5, 2016 12:41:26 PM



Votes:

0

Yes everything is up and running.

Thank you

Created on Jun 6, 2016 6:37:22 AM




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.