Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell在Windows上强制实施密码复杂性_Powershell_Powershell 2.0_Powershell 3.0_Powershell 4.0_Powershell 5.0 - Fatal编程技术网

使用Powershell在Windows上强制实施密码复杂性

使用Powershell在Windows上强制实施密码复杂性,powershell,powershell-2.0,powershell-3.0,powershell-4.0,powershell-5.0,Powershell,Powershell 2.0,Powershell 3.0,Powershell 4.0,Powershell 5.0,如何在使用Windows Powershell的工作组计算机上启用密码复杂性?我知道如何在域级别上实现这一点。我们有一些位于远程位置的计算机,它们没有域访问权限,因此它们在工作组中 这不是powershell的好解决方案。 这对于本地安全策略来说是可以的 转到run并键入SecPol.msc 转到帐户策略>密码策略>密码必须满足复杂性要求 设置为启用 设置最小密码长度 设置最大密码期限 因此,我决定编写一些函数,通过Powershell为您解决所有这些问题 您可以使用此功能获取和编辑安全策略Pa

如何在使用Windows Powershell的工作组计算机上启用密码复杂性?我知道如何在域级别上实现这一点。我们有一些位于远程位置的计算机,它们没有域访问权限,因此它们在工作组中

这不是powershell的好解决方案。 这对于本地安全策略来说是可以的

  • 转到run并键入SecPol.msc
  • 转到帐户策略>密码策略>密码必须满足复杂性要求
  • 设置为启用
  • 设置最小密码长度
  • 设置最大密码期限
  • 因此,我决定编写一些函数,通过Powershell为您解决所有这些问题

    您可以使用此功能获取和编辑安全策略
    Parse SecPol
    。这将把整个配置文件变成一个PSobject,这样您就可以更改属性并对它们进行排序,或者执行任何您想执行的操作

    下一个是
    Set SecPol
    ,它将允许您将对象重新保存回本地安全策略

    参数
    -CfgFile
    是要保存配置文件的位置

    下面是带有示例的完整脚本(必须以管理员身份运行)

    函数解析SecPol($CfgFile){
    secedit/export/cfg“$CfgFile”|输出空值
    $obj=新对象psobject
    $index=0
    $contents=获取内容$CfgFile-原始
    
    [regex]::Matches($contents,”(?可能与我重写的答案重复,以包含我制作的脚本,您可以使用。
    Function Parse-SecPol($CfgFile){ 
        secedit /export /cfg "$CfgFile" | out-null
        $obj = New-Object psobject
        $index = 0
        $contents = Get-Content $CfgFile -raw
        [regex]::Matches($contents,"(?<=\[)(.*)(?=\])") | %{
            $title = $_
            [regex]::Matches($contents,"(?<=\]).*?((?=\[)|(\Z))", [System.Text.RegularExpressions.RegexOptions]::Singleline)[$index] | %{
                $section = new-object psobject
                $_.value -split "\r\n" | ?{$_.length -gt 0} | %{
                    $value = [regex]::Match($_,"(?<=\=).*").value
                    $name = [regex]::Match($_,".*(?=\=)").value
                    $section | add-member -MemberType NoteProperty -Name $name.tostring().trim() -Value $value.tostring().trim() -ErrorAction SilentlyContinue | out-null
                }
                $obj | Add-Member -MemberType NoteProperty -Name $title -Value $section
            }
            $index += 1
        }
        return $obj
    }
    
    Function Set-SecPol($Object, $CfgFile){
       $SecPool.psobject.Properties.GetEnumerator() | %{
            "[$($_.Name)]"
            $_.Value | %{
                $_.psobject.Properties.GetEnumerator() | %{
                    "$($_.Name)=$($_.Value)"
                }
            }
        } | out-file $CfgFile -ErrorAction Stop
        secedit /configure /db c:\windows\security\local.sdb /cfg "$CfgFile" /areas SECURITYPOLICY
    }
    
    
    $SecPool = Parse-SecPol -CfgFile C:\test\Test.cgf
    $SecPool.'System Access'.PasswordComplexity = 1
    $SecPool.'System Access'.MinimumPasswordLength = 8
    $SecPool.'System Access'.MaximumPasswordAge = 60
    
    Set-SecPol -Object $SecPool -CfgFile C:\Test\Test.cfg