PWSH 7.2.1: Set-Service: Service * cannot be configured due to the following error: Access is denied.
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Open PWSH as Adminstrator via Start > PowerShell > PowerShell 7 (x64) > Run as Administrator and run the below command. In Windows PowerShell 5.1.x it works fine. Hence, seems a regression. I haven’t tried the command in any prior PWSH version. Also, SCPolicySvc is not the only service set-service fails to set with the same error message. However, it doesn’t fail to set all services, just certain ones.
Expected behavior
PS C:\WINDOWS\system32> set-service -name SCPolicySvc -startuptype disabled ; stop-service -name SCPolicySvc -force
PS C:\WINDOWS\system32>
Actual behavior
PS C:\Windows\System32> set-service -name SCPolicySvc -startuptype disabled ; stop-service -name SCPolicySvc -force
Set-Service: Service 'Smart Card Removal Policy (SCPolicySvc)' cannot be configured due to the following error: Access is denied.
PS C:\Windows\System32>
Error details
get-error
Exception :
Type :
Microsoft.PowerShell.Commands.ServiceCommandException
ServiceName : SCPolicySvc
Message : Service 'Smart Card Removal Policy
(SCPolicySvc)' cannot be configured due to the following error:
Access is denied.
InnerException :
Type : System.ComponentModel.Win32Exception
NativeErrorCode : 5
ErrorCode : -2147467259
Message : Access is denied.
HResult : -2147467259
HResult : -2146233087
TargetObject : System.ServiceProcess.ServiceController
CategoryInfo : PermissionDenied:
(System.ServiceProcess.ServiceController:ServiceController)
[Set-Service], ServiceCommandException
FullyQualifiedErrorId : CouldNotSetService,Microsoft.PowerSh
ell.Commands.SetServiceCommand
InvocationInfo :
MyCommand : Set-Service
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 359
Line : set-service -name SCPolicySvc
-startuptype disabled ; stop-service -name SCPolicySvc -force
PositionMessage : At line:1 char:1
+ set-service -name SCPolicySvc
-startuptype disabled ; stop-service -n …
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : set-service
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
PS C:\Windows\System32>
Environment data
$PSVersionTable
Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS C:\Windows\System32>
Visuals
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Unable to Start or Configure Windows Security Service on ...
Set-Service : Service 'Security Center (wscsvc)' cannot be configured due to the following error: Access is denied. At line:1 char:1.
Read more >Powershell New-Service gives permission denied
1 Answer. This is because you are running myService function in the current powershell instance and not in the new one you are...
Read more >Set-Service for remote machine failing. Access is denied.
Set-Service : Service 'Antivirus (AntivirusSvc)' cannot be configured due to the following error: Access is denied At line:1 char:52.
Read more >How to fix "Access is denied" error when using Windows ...
Find the Service that you want to modify · Open the Start menu and look for Command Prompt · Click Run as Administrator....
Read more >Untitled
Lxssmanager service access denied The LxssManager server really is Windows ... New issue PWSH 7.2.1: Set-Service: Service * cannot be configured due to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@iSazonov , on it. Thanks for the mention 😀.
/cc @kvprasoon