#PowerShell: Splatting a Local Hash Table in a Remote Session

I’m sure that most people who use PowerShell on a regular basis are familiar with the “Using” variable scope modifier which allows for the use of local variables in a remote session. This functionality was introduced with PowerShell version 3:


A fairly simple concept, right? But wait a minute, did you know that you can also define a local hash table to be used with splatting in a remote session using this same concept?


The previous example is a simple one, but this concept comes in handy when writing an advanced function where you’ve wrapped your function around PowerShell remoting like in the following example where I use a hash table from the local session to control the PassThru, WhatIf, and Confirm parameters that are taking place in the remote session:

The Start-MrAutoStoppedService function shown in the previous code example can be downloaded from my PowerShell repository on GitHub.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: