- 1 year ago
Run multiple winrm command in one line
To run multiple WinRM commands in one line, you can use a PowerShell script or a single command line that contains multiple commands separated by semicolons or line breaks. Here's how you can achieve it:
Using a PowerShell Script:
Create a PowerShell script file (e.g.,myscript.ps1
) that contains the multiple WinRM commands you want to run. Each command should be on a separate line. For example:powershell# myscript.ps1
Get-Process
Get-Service
Get-WmiObject Win32_ComputerSystem
Save the script file and then execute it remotely using the
Invoke-Command
cmdlet:powershellInvoke-Command -ComputerName <remote_computer> -ScriptBlock { .\myscript.ps1 }
Replace
<remote_computer>
with the name or IP address of the remote computer.Using a Single Command Line:
If you prefer to run multiple WinRM commands in a single command line, you can use line breaks or semicolons to separate the commands. For example:powershellwinrm invoke -uri http://<remote_computer>:5985/wsman -cred <username> -pas <password> -encoding utf-8 'Get-Process; Get-Service; Get-WmiObject Win32_ComputerSystem'
Replace
<remote_computer>
,<username>
, and<password>
with the appropriate values.
Please note that running multiple commands in a single line may become difficult to read and maintain as the number of commands increases. If you have a more complex scenario or require better organization, consider using a PowerShell script for better readability and maintainability.