Invoke-Command -ComputerName 远程计算机名 -ScriptBlock { 远程计算机上要执行的命令 } 例如,如果要在远程计算机上执行ipconfig命令,并在主机上显示输出,可以使用以下命令: 代码语言:txt 复制 Invoke-Command -ComputerName 远程计算机名 -ScriptBlock { ipconfig } 执行...
最常见的方法是使用Invoke-Command命令,它允许您在远程计算机上执行指定的命令或脚本块。以下是一种执行多条命令的示例: powershellCopy Code Invoke-Command-ComputerName"远程计算机名"-ScriptBlock{# 在这里可以放置要执行的多条命令Get-ServiceSpoolerGet-Process# 可以执行其他命令} 在上面的示例中,Invoke-Command指...
PowerShell 复制 Invoke-Command [[-ComputerName] <String[]>] [-Credential <PSCredential>] [-Port <Int32>] [-UseSSL] [-ConfigurationName <String>] [-ApplicationName <String>] [-ThrottleLimit <Int32>] [-AsJob] [-InDisconnectedSession] [-SessionName <String[]>] [-HideComputerName] [...
PowerShell 複製 Invoke-Command [-AsJob] [-HideComputerName] [-FilePath] <String> -SSHConnection <Hashtable[]> [-RemoteDebug] [-InputObject <PSObject>] [-ArgumentList <Object[]>] [<CommonParameters>]DescriptionCmdlet 會在 Invoke-Command 本機或遠端電腦上執行命令,並從命令傳回所有輸出,包括...
If the command is a PowerShell command, make sure that the instances have the PowerShell module configured. You can configure the command to run only once on the instances. You can configure the command to run on the instances based on a schedule. The schedule is specified by Frequency. Th...
For example, to terminate a process on a remote computer, you can run the following command: PowerShell Copy Get-CimInstance -ClassName Win32_Process -Filter "Name='notepad.exe'" -Computername LON-DC1 | Invoke-CimMethod -MethodName Terminate Next unit: Knowledge check Previou...
Module: Microsoft.PowerShell.Utility Runs commands or expressions on the local computer.SyntaxPowerShell Copy Invoke-Expression [-Command] <String> [<CommonParameters>]DescriptionThe Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the expression ...
该方法最cool点在于对抗那些PowerShell remoting开启的Remote系统。 invoke-command -scriptblock {Write-Host "My voice is my passport, verify me."} 如下命令,可用来从一个远程系统上抓取执行策略同时运用到本地计算机中. invoke-command -computername Server01 -scriptblock {get-executionpolicy} | set-executio...
invoke-command -ComputerName pc1 -scriptblock {Get-Service} Example 2: Get services on multiple computers To run PowerShell commands on multiple remote computers just separate them by a comma. You can use hostname or IP address. invoke-command -ComputerName pc1, srv-vm1 -scriptblock {Get-...
在网上看到个类似的函数,支持查询远程机器的系统信息,但不是用的Invoke-Command命令:function Get-SystemInfo { param($ComputerName = $env:COMPUTERNAME)header = 'Hostname','OSName','OSVersion','OSManufacturer','OSConfiguration','OS Build Type','RegisteredOwner','RegisteredOrganization','...