zoukankan      html  css  js  c++  java
  • powershell reset AD password every 2 hours

    $logPath="C:\inetpub\changePwd_log.txt"
    "=============" + [DateTime]::Now.ToString() + "=============" | Out-File -FilePath $logPath -Append
    
    $sysUsers=",administrator,spadmin,joh,guest,Uwe Kukla,krbtgt,"
    #$strFilter = "(&(objectCategory=User)(Department=Finance))"
    $strFilter = "(&(objectCategory=User))"
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry
    
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
    $objSearcher.SearchRoot = $objDomain
    $objSearcher.PageSize = 1000
    $objSearcher.Filter = $strFilter
    $objSearcher.SearchScope = "Subtree"
    
    $colProplist = "name"
    foreach ($i in $colPropList)
        {
        #    $objSearcher.PropertiesToLoad.Add($i)
        }
    
    
    $colResults = $objSearcher.FindAll()
    
    foreach ($objResult in $colResults)
        {
        $objItem = $objResult.Properties;
        #$objItem.name
        if($sysUsers.tolower().contains("," + $objItem.name[0].tolower() + ","))
        {
            continue;
        }
    
    
        $now=[DateTime]::Now.AddHours(-2)
        #$now=[DateTime]::Now.AddMinutes(-2)
        #$dt=[datetime]::FromFileTimeUtc($objItem.properties.pwdlastset.value)
        $dt=[datetime]::fromfiletime($objItem.pwdlastset[0])
        #write-host($objItem.name[0])
        #if($objItem.name[0].ToLower().Equals("test4"))
        #{
        #    write-host($objItem.name[0] + "    " + $dt + "    " + $now)
        #}
        if($now -gt $dt)
        {
            $secure = convertto-securestring "Abaa11" -asplaintext -force
            #write-host($objItem.distinguishedname[0])
            #Set-ADAccountPassword -Identity $objItem.name[0] -NewPassword $secure -reset
            Set-ADAccountPassword -Identity $objItem.distinguishedname[0] -NewPassword $secure -reset
            #write-host($objItem.name[0] + "    " + $dt.tostring())    
            $objItem.name[0] + "    " + $dt.tostring() + "      " + [DateTime]::Now.tostring() | Out-File -FilePath $logPath -Append
        }
        ##Write-Host ([DateTime]::Now.AddHours(-2).ToString())
        #$objItem.pwdlastset
        }
  • 相关阅读:
    element 三级复选框
    element 复选框问题
    vue 的样式穿透(深度选择器) >>>
    随笔,用于直接复制粘贴
    element 弹窗无法重新赋值的问题
    @vue/cli 4.2.3版本的本地json读取和跨域配置(与旧版本vue不同)
    element表格及接口的对接
    axios的post请求即自动刷新
    Puppeteer 安装及失败原因
    Redis的安装
  • 原文地址:https://www.cnblogs.com/zyip/p/3007087.html
Copyright © 2011-2022 走看看