okrus
okrus

Reputation: 91

Powershell command to set service 'log on' to 'LocalSystem'

What I want to do: Set 'Log on' to 'LocalSystem' on all windows services where the display name starts with 'CTM_'

I have found a powershell command to stop/start all services where the name starts with 'CTM_':

Get-Service | Where-Object {$.displayName.StartsWith("CTM")} | Start-Service

And I have found a powershell commando to set a specific service 'log on' to 'LocalSystem':

sc.exe config "ServiceName" obj="Localsystem"

What I am strugling with, is to find a command to run the last powershell command on all windows services where the display name starts with a give text, for example 'CTM_'

Image

Upvotes: 0

Views: 1311

Answers (1)

Toni
Toni

Reputation: 1816

You can use the CIM cmdlets, e.g.

#Get all services where the name starts with 'CTM_' and the currently configured starName is not localSystem, set startname to localsystem

get-ciminstance -query "select name from win32_service where name like 'CTM_%' and startname <> 'localsystem'" | Invoke-CimMethod -Name change -Arguments @{startname='localsystem'}

Upvotes: 1

Related Questions