Using Set-Date in a Powershell script fails due to permissions

373 views Asked by At

When trying to run Set-Date in my powershell script it fails because it claims to require more permissions. I have added the groups Users and even Everyone to the Adjust system time Local Security Policy. Of course I could run it elevated to admin, but I'm trying to avoid that. What's extra odd is that this script has worked fine so far on some machines.

Powershell version is 5.1, windows version is 10 Enterprise 2016 (v1607)

The error message:

PS > Set-Date "2021-06-07T10:00"
Set-Date : Klienten har ikke nødvendig tilgangsnivå
At line:1 char:1
+ Set-Date "2021-06-07T10:00"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-Date], Win32Exception
    + FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand
1

There are 1 answers

0
Henrik Erstad On BEST ANSWER

Though I do not fully understand why, it works when you disable the policy User Account Control: Run all administrators in Admin Approval Mode.