PowerShell的:密码必须更改下次登录时密码过期1天

编程入门 行业动态 更新时间:2024-10-27 18:34:22
本文介绍了PowerShell的:密码必须更改下次登录时密码过期1天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能有人帮我修改如下:我需要一个的PowerShell 脚本搜索特定的组织单元有很多的用户和组:密码必须改变@下次登录时,如果密码1天之内。

到期

我已经有以下脚本:

$ maxPwdAge =(GET-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days $1天=(获取最新).AddDays(1- $ maxPwdAge).ToShortDateString() 获取-ADUser便有-filter {启用当量$真-and PasswordNeverExpires当量$假-and PasswordLastSet -gt 0} -Properties * |其中{($ _ PasswordLastSet).ToShortDateString()当量$1天} |选择 *

解决方案

您应该改为比较的DateTime 的物品直接,你平淡不需要 ToShortDateString()转换为在PowerShell中比较日期。同样在 SELECT * 是多余的,只能败坏对象的返回类型。

$1天=(获取最新).AddDays(1- $ maxPwdAge) 获取-ADUser便有-filter {启用当量$真-and PasswordNeverExpires当量$假-and PasswordLastSet -gt 0} -Properties * | 其中{$ _。PasswordLastSet -ge $1天}

应该做的。

Could someone help me with the following: I need a PowerShell script that searches a specific Organization Unit with a lot of users and sets: Password must change @ next logon if the password expires within 1 day.

I already have the following script:

$maxPwdAge=(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days $1day=(get-date).AddDays(1-$maxPwdAge).ToShortDateString() Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and PasswordLastSet -gt 0} –Properties * | where {($_.PasswordLastSet).ToShortDateString() -eq $1day} | select *

解决方案

You should instead compare DateTime objects directly, you plain don't need ToShortDateString() conversion to compare dates in Powershell. Also last select * is superfluous and only spoils the return type of an object.

$1day=(get-date).AddDays(1-$maxPwdAge) Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and PasswordLastSet -gt 0} –Properties * | where {$_.PasswordLastSet -ge $1day}

Should do.

更多推荐

PowerShell的:密码必须更改下次登录时密码过期1天

本文发布于:2023-07-14 17:50:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密码   下次   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!