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.


Article Comments

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


Jun, 2016 - Permalink

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>


Jun, 2016 - Permalink

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


Jun, 2016 - Permalink

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


Jun, 2016 - Permalink

Yes everything is up and running.

Thank you


Jun, 2016 - Permalink