Collections:
Other Resources:
"Invoke-Command" Cmdlet in Windows PowerShell
What is the "Invoke-Command" cmdlet in Windows PowerShell?
✍: FYIcenter.com
You can use the "Invoke-Command" cmdlet to run
commands on remote computers in one-time PSSession.
With a single Invoke-Command command, you can run commands on
multiple computers.
"Invoke-Command" cmdlet can also be used to run commands on an existing PSSession by using the "-session $s" option to specify the existing session.
The following example runs the "query user" cmdlet on the remote computer "office-server":
PS C:\fyicenter> Invoke-Command office-server {query user} USERNAME SESSIONNAME ID STATE IDLE TIME fyicenter rdp-tcp#0 2 Active .
The following example runs the the PowerShell script, test.ps1, on the remote computer "office-server". Note that "test.ps1" is located on the local computer not the remote computer.
PS C:\fyicenter> Invoke-Command office-server -FilePath test.ps1
The following example runs two script on the same existing PSSession. The first script creates a variable $p in the PSSession. The second script uses the value of variable $p. Note that "-ScriptBlock {...}" option is used, "$p=Get-Process PowerShell" and "$p.VirtualMemorySize" are scripts, not cmdlets.
PS C:\fyicenter> $s = New-PSSession office-server PS C:\fyicenter>Invoke-Command -Session $s -ScriptBlock {$p=Get-Process PowerShell} PS C:\fyicenter>Invoke-Command -Session $s -ScriptBlock {$p.VirtualMemorySize} 17930240
⇒ Managing Windows PowerShell Background Jobs
⇐ Example of PowerShell Session on Remote Computer
2016-10-13, 6749🔥, 0💬
Popular Posts:
The day I received Windows 10, everything seemed to work. The next day Microsoft Solitaire Collectio...
Can I disable Windows service "PCAngel.exe - PC Angel" to speedup my computer? Windows service "PCAn...
How to remove NetZero Toolbar from Internet Explorer (IE) 7 browser? NetZero Toolbar offers you nice...
What is the file extension .IFO on a DVD-Video disc? .IFO is the file extension used on a DVD-Video ...
What is "Net Driver HPZ12" in my Windows 7 service list? And how is "Net Driver HPZ12" service relat...