我正在尝试远程停止/启动Windows服务。但是,如果删除-Computer
参数,则它在本地计算机上运行良好。如果添加-Computer
参数,它将引发异常。我想念什么吗?
New-CimInstance : Unable to resolve the parameter set name. At D:\DevOps\Scripts\StartStopvNextService.ps1:6 char:16 + ... yInstance = New-CimInstance -Namespace root/cimv2 -ClassName Win32_En ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-CimInstance], PSArgumentException + FullyQualifiedErrorId : Argument,Microsoft.Management.Infrastructure.CimCmdlets.NewCimInstanceCommand
Param(
[string]$Name,
[string]$Computer
)
Import-Module CimCmdlets
$keyInstance = New-CimInstance -Namespace root/cimv2 -ClassName Win32_Service -Key @('Name') -Property @{Name=$Name;} -ComputerName $Computer -ClientOnly
Invoke-CimMethod $keyInstance -MethodName StartService