Invoke-Command wrapper function

A quick post this time about something that might be helpful for others, something that saves me from typing too much 🙂

I’ve noticed over the last week that I’ve been doing various remoting commands through Invoke-Command to the same machines, which require additional credentials to access.

Why re-type something when you can automate it 🙂

Before

I used to have to do the following:

Where my SCCM servers are in another forest as my management machine and $CredStore is my personal Credential folder which contains credentials for various systems/domains, as I use these regularly and I’m lazy

After

After some tinkering around and a great tip found on Thomas Maurer’s site, I’ve narrowed it down to:

I’ve personally decided to keep the 2 variables in my $profile as I tend to use those for other functions as well, but otherwise I would recommend placing these in the begin {} block.

The magic here is the converting of a string to an actual scriptblock by the PowerShell engine, accomplished by the following piece of code:

The Code

 

Happy Scripting! 🙂

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Robert

It never hurts to Get-Help

Leave a Reply

Your email address will not be published. Required fields are marked *