【发布时间】:2021-03-04 17:36:16
【问题描述】:
我正在编写一个脚本来更改 Windows 服务器中的本地安全策略。当我在 PowerShell 提示符下自行运行这些命令时,它们运行良好。但是,当我运行脚本时,我收到了 "Unexpected token 'PasswordComplexity' in expression or statement." 错误。
问题似乎源于脚本似乎没有执行secedit 命令,因此get-content 行没有要编辑的文件。
为什么secedit 没有运行?我尝试将secedit 命令放在if 语句之外,但得到了相同的结果。
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
}
【问题讨论】:
标签: powershell