Windows PowerShell 按数据范围过滤
Windows PowerShell Filtering by data range
我有一个 powershell 脚本可以从我们的 SSO 应用程序中获取停用的帐户,但我想将其过滤到仅在 90 天前停用的帐户。
然后我有另一个脚本来获取结果并从 SSO 应用程序中删除这些用户。
你能告诉我如何向以下脚本添加过滤器以排除 StatusChanged 日期距当前日期超过 90 天的结果吗?
$users = oktaListDeprovisionedUsers -oOrg PREV
$toexport = New-Object System.Collections.ArrayList
Foreach ($u in $users)
{
$line = @{
status = $u.status
employeeid = $u.profile.employeeNumber
firstName = $u.profile.firstName
lastName = $u.profile.lastName
email = $u.profile.email
department = $u.profile.department
supervisor = $u.profile.manager
created = $u.created
lastUpdated = $u.lastUpdated
login = $u.profile.login
title = $u.profile.title
GroupName = $u.profile.Group_Name
Organization = $u.profile.organization
Location = $u.profile.workday_location
User_type = $u.profile.userType
StatusChanged = $u.StatusChanged
}
$obj = New-Object psobject -Property $line
$_c = $toexport.Add($obj)
}
#Path for utility will have to be changed to a more generic location.
$toexport | Select-Object "login", "StatusChanged", "employeeid", "firstName","lastName", "email", "title","supervisor","department","Organization","Location", "GroupName" | >Export-Csv -Path "C:\OktaExport\user-list.csv" -NoTypeInformation
您可以通过 Where-Object
过滤 $users 对象
$users = $users | Where-Object{((Get-Date) - $_.StatusChanged).TotalDays -gt 90}
将此添加到脚本的第二行。
我有一个 powershell 脚本可以从我们的 SSO 应用程序中获取停用的帐户,但我想将其过滤到仅在 90 天前停用的帐户。 然后我有另一个脚本来获取结果并从 SSO 应用程序中删除这些用户。
你能告诉我如何向以下脚本添加过滤器以排除 StatusChanged 日期距当前日期超过 90 天的结果吗?
$users = oktaListDeprovisionedUsers -oOrg PREV
$toexport = New-Object System.Collections.ArrayList
Foreach ($u in $users)
{
$line = @{
status = $u.status
employeeid = $u.profile.employeeNumber
firstName = $u.profile.firstName
lastName = $u.profile.lastName
email = $u.profile.email
department = $u.profile.department
supervisor = $u.profile.manager
created = $u.created
lastUpdated = $u.lastUpdated
login = $u.profile.login
title = $u.profile.title
GroupName = $u.profile.Group_Name
Organization = $u.profile.organization
Location = $u.profile.workday_location
User_type = $u.profile.userType
StatusChanged = $u.StatusChanged
}
$obj = New-Object psobject -Property $line
$_c = $toexport.Add($obj)
}
#Path for utility will have to be changed to a more generic location.
$toexport | Select-Object "login", "StatusChanged", "employeeid", "firstName","lastName", "email", "title","supervisor","department","Organization","Location", "GroupName" | >Export-Csv -Path "C:\OktaExport\user-list.csv" -NoTypeInformation
您可以通过 Where-Object
过滤 $users 对象$users = $users | Where-Object{((Get-Date) - $_.StatusChanged).TotalDays -gt 90}
将此添加到脚本的第二行。