Search code examples
powershellgroup-policy

How to set value for local group policy(gpedit.msc) using power shell script


I want to access this path Computer Configuration\Policies\Windows Settings\Security Settings\Account Policies\Password Policy\Maximum password age in local group policy editor and modify its value through powershell script. I have tried to import module group (Get-Command -Module group*) but no methods/module is found.I have tried the following way in powershell and it didn't work.

Set-ItemProperty -Path \Computer Configuration\Windows Settings\Security Settings\Account Policies\Password Policy -Name Maximum password age -Value 20

Can someone help me in modifying the value through powershell scripting.

I am new to powershell scripting,so please ignore if any wrong info is provided.


Solution

  • For parameters like max password age, I think best way is to use net.exe commant. Try to execute

    net.exe accounts /? 
    

    For more complicated group policies in computer without domain, you can prepare policies in one computer, export it to file, and inport in other computers, by using secedit.exe

    Try to google secedit /export, secedit /import usage

    You can call secedit from powershell without any problems