A very short post simply to expose a cool trick that will most likley help all of us out when we are doing PowerShell remoting and answer the following question: How to run a local powershell function remotley ?

I stumbled on this topic because I wrote this function locally, and I developped it because I was logic for me that I would only be able to work locally.

Eventually I ended up needing to get that same information from remote machines, but I did not want to add any “computerName” parameter to my function. The idea was to keep it as simply as possible.

My function was a function that retrieves the software updates that are currently installed on the machine. It is based on a ComObject, which doesn’t have native remoting capabilities.

The function is named “Get-WindowsUpdates” (the content of this function is yet not that important right now since this will work for any function. But if you are curious can get it right here –> http://powershelldistrict.com/get-windowsupdates/). In a report script (which I will blog about shortly too ;)) I actually needed to get this information as well. I then asked my self  How to run a  a local powershell function remotley ?

How to run a local powershell function remotley ?

The answer is Invoke-Command in combination with the function: ps drive. See my example below

[important]Use Invoke-Command using the Function PSdrive to make your local functions available remotley.[/important]

Voila, pretty simple, but this will defenitly save you some time and efforts when remoting is needed.


By | 2016-10-19T21:00:15+00:00 November 11th, 2014|Functions, PowerShell, PowerShell remoting|0 Comments

About the Author:

Stéphane is a dynamic and passionate Cloud and datacenter Microsoft MVP since. He is the founder of the Basel PowerShell user Group (BPUG), the co-founder of the French Speaking PowerShell UserGroup (FRPSUG), author, blogger, and received the community award "PowerShell Hero" from PowerShell.org. Stéphane has implemented microsoft infrastructure solutions in various countries of Europe and is currently working in Basel / Switzerland. Stéphane help his clients to reduce their global infrastructure costs by implementing Microsft infrastructure solutions by combining great products such as System Center, Windows Server, with heavy automation using Windows PowerShell. Stéphane loves languages, Belgium beer, French cheese and French Wine. If any of these topics are of your interest, don't hesitate to come and say hi.

Leave a Reply

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

%d bloggers like this: