PowerShell Invoke-Command pipelines tip

I was working with Orchestrator recently and needed to implement some PowerShell to remotely manage Microsoft Exchange 2010 so I suppose I have 2 tips on one for you here. If you are trying to use the Exchange Admin Integration Pack you should be aware that this only supports basic authentication to your Exchange environment. If you are using Kerberos (as you probably should be) then this integration pack will be a no go for you. This means that you are left to explore you options which will probably include:

You should look at each one to see if it can successfully do what you need but I wanted to share what seems to be a little known limitation of Invoke-Command. This is quite a favourable option however it is limited to running a single pipeline at a time, try it for yourself and you will see that you can’t get information and then format it in the same command for example. The way around this would be to store the pipelines in a variable in the script block of Invoke-Command (or pass them in with –ArgumentList) and then simply call the cmdlet with a variable prefixed or suffixed. Example below:

Invoke Command basic syntax

Invoke-Command –ScriptBlock {

Do-Stuff –Here }

If you try Do-Stuff –Here | Select Name | Format-Table –HideTableHeaders it will fail.

You should use something like this

Invoke-Command –ScriptBlock {

$Select = | Select Name

$Format = $Select | Format-Table –HideTableHeaders

Do-Stuff –Here $Format

Give that a go and see how you get on. I’d be happy to know the outcome as these things can be a little hit and miss depending on your specific requirements.

This post was originally published on wmug.co.uk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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