Asked by:
Unable to create New-CimInstance

Question
-
Hello,
I'm trying to stop and start windows service remotely; however, my script below is only working if it is running locally without -Computer parameter. If I add -Computer parameter, it is throwing an exception below. Please advise.
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.NewCimInstanceCommandParam( [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
Best Regards,
Andy Pham
Best Regards, Andy Pham
Monday, February 4, 2019 7:11 PM
All replies
-
You cannot use New-CimInstance to manage services.
Make it easy
Get-Service -Name <name> -Computer PC1 | Start-Service
\_(ツ)_/
- Edited by jrv Monday, February 4, 2019 7:41 PM
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Tuesday, February 5, 2019 6:48 AM
Monday, February 4, 2019 7:40 PM -
Get-Service | Start-Service is exactly like the Cim commands but has a PS wrapper for convenience.
For Cim we would do this:
$servicename = 'spooler' $computername = 'Alpha' Get-CimInstance Win32_Service -Filter "Name='$servicename'" -CimSession $computername | Invoke-CimMethod -MethodName StartService
Cim CmdLets do not need to be imported. They are a fundamental part of PowerShell.
\_(ツ)_/
- Edited by jrv Monday, February 4, 2019 7:52 PM
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Tuesday, February 5, 2019 6:48 AM
- Unproposed as answer by AndyPham Wednesday, February 6, 2019 11:02 PM
Monday, February 4, 2019 7:51 PM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
LeeJust do it.
Tuesday, February 5, 2019 6:49 AM -
Do apology for late responded. Got error below. Please advise
Get-CimInstance : WinRM cannot process the request. The following error with errorcode 0x8009030e occurred while using Kerberos authentication: A specified
logon session does not exist. It may already have been terminated.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does not exist.
-The client and remote computers are in different domains and there is no trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command: winrm help config.
At D:\DevOps\Scripts\StartStopvNextService.ps1:13 char:1
+ Get-CimInstance Win32_Service -Filter "Name='$servicename'" -CimSessi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070520,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName :
Best Regards, Andy Pham
Wednesday, February 6, 2019 11:04 PM -
You must be an admin on the remote system. The system must be correctly joined to your domain. The error clearly states that it cannot authenticate with your credentials.
\_(ツ)_/
Wednesday, February 6, 2019 11:26 PM -
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Lee
Just do it.
Thursday, February 21, 2019 6:36 AM