12

I was wondering is it possible to pass a tiny script into the ScriptBlock parameter but do it all in one line?

For instance, I want to run the following 2 commands:

import-module lync get-csuser

I can do this if I have a powershell script file and call that file explicitly. The contents of the script look like this

invoke-command -ComputerName mycomputer.mylab.com -ScriptBlock {
import-module lync
get-csuser
}

I want to be able to do the above without putting this into a temporary script file and do it on one lime. Is this possible?

Thanks

1 Answer 1

20

You can use ; to do this. In PowerShell, the semicolon is a statement separator and allows you to use multiple statements on the same line.

invoke-command -ComputerName mycomputer.mylab.com -ScriptBlock { import-module lync ; get-csuser }

The semi-colon is among a handy set of characters that you can use to format things to your needs. Another example is using a backtick to split a command across multiple lines.

Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic, glad to know PS has a ; separator. Thanks so much for your quick reply! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.