代码之家  ›  专栏  ›  技术社区  ›  Rakha

invoke wmimethod-快速修复psremoting/winrm问题(用于调用命令用法)

  •  0
  • Rakha  · 技术社区  · 7 年前

    如果由于winrm未运行或psremoting被禁用而无法使用invoke命令访问您的计算机,这里是一个很好的、肯定的方法,我每次都能找到工作,至少在我的环境中是这样:

     $target_comp = "abc1234"
    
     Invoke-WmiMethod -ComputerName $target_comp -Path win32_process -Name create -ArgumentList "powershell.exe -command Enable-PSRemoting -SkipNetworkProfileCheck -Force"
     Invoke-WmiMethod -ComputerName $target_comp -Path win32_process -Name create -ArgumentList "powershell.exe -command winrm quickconfig -quiet"
    
    
     do {
         $testpsremoting = invoke-command -computername $target_comp -scriptblock {"test"}
        } while (!$testpsremoting) 
    
    
    
        #REST OF CODE
    

    说明:

    -声明计算机名的变量。
    -运行这两个命令,通过调用wmimethod启用psremoting和设置winrm。
    *由于invoke wmimethod在不等待命令实际执行的情况下立即返回:
    -循环运行,直到psremoting被启用(直到test invoke命令工作)。

    不再有调用命令问题!尽情享受,尽情享受。

    2 回复  |  直到 7 年前
        1
  •  0
  •   Bonneau21    7 年前

    您可以使用get wmi直接获取结果

    Get-WmiObject Win32_service -ComputerName $poste | select State,Name,DisplayName
    
        2
  •  0
  •   Rakha    7 年前

    问题已更改,以便为社区提供答案和有用的解决方案。