问题描述
请注意,我是POWERSHELL的新人
好吧,我需要获取密码在特定日期之前过期的多个用户的过期密码。我需要用户名和用户的电子邮件。我没有得到正确的输出。我不断收到一条消息,上面写着InputObject。我不确定要在此处添加什么,而且我知道我丢失了一些内容。
请参见下文
False
解决方法
我链接到的网络搜索会给您这些文章...
Get-ADUser: Getting Active Directory Users Info via PowerShell
您还可以使用Windows Server ADAC通过GUI单击来为您编写基准代码,您可以根据需要进行调整。
...和帮助文件,将为您提供正确构建此文件所需的一切
# Get specifics for a module,cmdlet,or function
(Get-Command -Name Get-ADUser).Parameters
(Get-Command -Name Get-ADUser).Parameters.Keys
Get-help -Name Get-ADUser -Examples
# Results
<#
Get-ADUser -Filter * -SearchBase "OU=Finance,OU=UserAccounts,DC=FABRIKAM,DC=COM"
Get-ADUser -Filter 'Name -like "*SvcAccount"' | FT Name,SamAccountName -A
Get-ADUser GlenJohn -Properties *
Get-ADUser -Filter {Name -eq "GlenJohn"} -SearchBase "DC=AppNC" -Properties mail -Server lds.Fabrikam.com:50000
#>
Get-help -Name Get-ADUser -Full
Get-help -Name Get-ADUser -Online
我对文章中的代码做了一些修改,如propertyNames中的空格, 变量,字段,文件名等,这些都是不必要的麻烦。
<#
Get Password Expiry Date of all Enabled AD Users
The following powershell script find all the enabled Active Directory users
whose PasswordNeverExpires flag value is equal to False and list the attribute
value samAccountName and Password Expire Date. The Active Directory computed
attribute msDS-UserPasswordExpiryTimeComputed is timeStamp attribute and its
value will be stored as integer,so we are using expression to convert timestamp
value into normal date time.
#>
Import-Module ActiveDirectory
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties 'SamAccountName','msDS-UserPasswordExpiryTimeComputed' |
Select-Object -Property 'SamAccountName',@{
Name = 'PasswordExpiryDate'
Expression = {[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}
} |
Where-Object -Property 'PasswordExpiryDate' -LE (Get-Date).AddDays(20) |
Export-Csv -Path 'D:\Temp\PasswordExpiryReport.Csv' -NoTypeInformation -Encoding UTF8
<#
You can add any extra attributes that are supported/available in Active Directory property listing.
If you want to add the attributes mail and pwdLastset with this script,you can
simply add these attributes as comma separated values.
#>
Import-Module ActiveDirectory
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties 'SamAccountName','mail','pwdLastSet','Name','DisplayName',@{
Name = 'PasswordLastSet'
Expression = {[datetime]::FromFileTime($_."pwdLastSet")}
},@{
Name = 'PasswordExpiryDate'
Expression = {[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}
} |
Where-Object -Property 'PasswordExpiryDate' -LE (Get-Date).AddDays(20) |
Export-Csv -Path 'D:\Temp\PasswordExpiryReport.Csv' -NoTypeInformation -Encoding UTF8