1

My code here should disable services in the list. But I get an error that

method invocation failed because system string doesn't contain a a method named ChangeStartMode

(gwmi win32_service -filter "name = 'SharedAccess' Or name = 'cx2Svc' OR name = 'NetTcpPortSharing' OR name = 'RemoteAccess' OR name = 'AxInstSV' OR name = 'SensrSvc' OR name = 'ALG' OR name = 'AppMgmt' OR name = 'BDESVC' OR name = 'bthserv' OR name = 'PeerDistSvc' OR name = 'CertPropSvc' OR name = 'VaultSvc' OR name = 'DPS' OR name = 'WdiServiceHost' OR name = 'WdiSystemHost' OR name = 'TrkWks' OR name = 'EFS' OR name = 'Fax' OR name = 'fdPHost' OR name = 'FDResPub' OR name = 'hkmsvc' OR name = 'hidserv' OR name = 'UI0Detect' OR name = 'iphlpsvc' OR name = 'lltdsvc' OR name = 'MSiSCSI' OR name = 'Netlogon' OR name = 'napagent' OR name = 'CscService' OR name = 'WPCSvc' OR name = 'PNRPsvc' OR name = 'p2psvc' OR name = 'p2pimsvc' OR name = 'IPBusEnum' OR name = 'PNRPAutoReg' OR name = 'WPDBusEnum' OR name = 'wercplsupport' OR name = 'PcaSvc'").ChangeStartMode("Disabled")

I have tried changing the quoting and tried making it one service. I also tried using ChangeServiceStart and ChangeServiceStartType which I found online for other people's scripts but none of those worked. I have also tried this on several computers in powershell v1.0 v2.0 and one with WMI 3.0

3
  • Are you sure The command given here is what you are trying? It works as expected for me. Can you give the exact simplified case of the one you tried with just one service? Commented Sep 1, 2014 at 17:32
  • (gwmi win32_service -filter "name = 'SharedAccess'").ChangeStartMode("Disabled") Am I structuring this correctly? Commented Sep 1, 2014 at 17:56
  • Also I used a USB wrote it to a text file and have been copy/pasting it when trying it or posting it here. Commented Sep 1, 2014 at 18:02

1 Answer 1

1

You'll need to use foreach or ForEach-Object to call that method for each result returned -

Simplified example using ForEach-Object -

(gwmi win32_service -filter "name = 'SharedAccess' Or name = 'cx2Svc') | 
    ForEach-Object {$_.ChangeStartMode("Disabled")}

You could also use the service cmdlets for this activity -

Get-Service -Name SharedAccess, cx2Svc -EA 0 | 
   Set-Service -StartupType Disabled
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I will give it a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.