Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected token errors in Powershell

Tags:

I'm working on a script to change local security policy in windows server. When I run these commands by themselves in a PowerShell prompt, they work fine. However when I run the script I am getting an "Unexpected token 'PasswordComplexity' in expression or statement." error.

The problem seems to stem from the fact that the script doesn't seem to be executing the secedit command, so the get-content lines have no file to edit.

Why is secedit not running? I've tried putting the secedit command outside of the if statement, but get the same results.

if ($win_ver -match "Server"){
    #export current secuirty policy
    secedit /export /cfg c:\new.cfg
    start-sleep -s 10
    #Disable Password Complexity
    ((get-content c:\new.cfg) -replace (‘PasswordComplexity = 1′, ‘PasswordComplexity = 0′)) | Out-File c:\new.cfg
    #Disable password expiration
    ((get-content c:\new.cfg) -replace (‘MaximumPasswordAge = 42′, ‘MaximumPasswordAge = -1′)) | Out-File c:\new.cfg
    #disable minmum password length
    ((get-content c:\new.cfg) -replace (‘MinimumPasswordLength = 6′, ‘MinimumPasswordLength = 1′)) | Out-File c:\new.cfg
    #import new security settings
    secedit /configure /db $env:windir\security\new.sdb /cfg c:\new.cfg /areas SECURITYPOLICY
}