Skip to main content

Making a remote PowerShell connection

Author
John Billekens
Technical Consultant | End User Computing

In this article I will make a short description how to make a remote PowerShell connection. I needed this for a job once, tried to make a remote PowerShell connection from a Non Domain Joined machine to a Domain Joined server. I needed to re-configure the server first before making a connection. With the following code you can try and test the connection:

$computer = "controller01.domain.local"
$credential = get-credential
Invoke-Command -ScriptBlock {get-host} -ComputerName $computer -Credential $credential

At the popup enter the credentials. If you are lucky, a successful connection can be made, but in my case this wasn’t so. I got a nice error. This meant that I needed to make a secure connection (client machine was not Domain Joined). You can create a secure remote connection by adding the -UseSSL option

Invoke-Command -ScriptBlock {get-host} -ComputerName $computer -Credential $credential -UseSSL

But that alone is not enough, you also need to configure the server you are connecting to. You can configure the server to listen to secure connection by running the following command.

winrm quickconfig -transport:https

Before a secure connection can be setup, you need to have a certificate (in the personal computer store) that matches the fqdn of your server. If you don’t have a (correct) certificate you can get an error. If you have the certificate in place, run the following command again.

winrm quickconfig -transport:https

Note: additional configuration regarding security may be required! These are just the default configuration. Depending on you certificate used you may have to configure the “-SkipRevocationCheck” and “-SkipCACheck” to make a successful connection.

$computer = "controller01.domain.local"
$credential = get-credential
$sessionOption = New-PSSessionOption -SkipRevocationCheck -SkipCACheck
Invoke-Command -ScriptBlock {get-host} -ComputerName $computer -Credential $credential -SessionOption $sessionOption -UseSSL

And I had a successful connection. I hope with sharing this knowledge I could help you to.

Related

Let's Encrypt Certificates on a NetScaler

··39 mins
For a while now it’s possible to use Let’s Encrypt certificates, they are trusted (cross signed), secure and most of all FREE! There are already a lot of tools available to generate these certificates. I haven’t come across a tool or script to generate these certificates and upload them to a Citrix NetScaler. So I thought why not build it myself. I already tried it in a previous attempt, but I wanted more automation and thus I created this version. To learn more about the Let’s Encrypt, check how it works.. What my script does in very basic steps (for example you want a certificate for www.domain.com): Ask LE (Let’s Encrypt) to validate “www.domain.com” (1) LE returns data (2) among them:

Create offline backups of the NetScaler config

··8 mins
I’ve created a PowerShell script that can be used to generate an (offline) backup of a Citrix NetScaler. If you want you can use the supplied batchfile for example to schedule the backup in Scheduled Tasks to run everyday. Some more information about the parameters used:

Spontaneously changing default printer

··2 mins
Yesterday I was at a Customers location and they had an issue with their printers on the XenDesktop VDI environment. Some users are using Exact to print all kinds of labels, in this case a Zebra label printer. And while they were printing labels, the label printer was set automagically as default. They started noticing this because when they wanted to print other (A4) reports, the layout was wrong and some information fell of the report. They could change the default printer back to the MFP, but when they printed labels again, you’ll get it right? I recently helped them move from Windows 10 LTSB 2015 (1507) to Windows 10 LTSB 2016 (1607) and they started noticing this issue after the switch to the new Windows version. So what could it be? Turned out to be a setting in Windows… After changing this, the issue was gone. You can change it in “Settings”, “Devices”, “Printers & Scanners” and change the setting “Let Windows manage my Default printer” to off. Or you can set the following registry key: