cancel
Showing results for 
Search instead for 
Did you mean: 
Disclaimer
JUMPCLOUD EXPRESSLY DISCLAIMS ALL REPRESENTATIONS, WARRANTIES, CONDITIONS, AND LIABILITIES OF ANY KIND ARISING FROM OR RELATED TO THIRD-PARTY SOFTWARE, SCRIPTS, REPOSITORIES, AND APIS. JUMPCLOUD IS NOT REQUIRED TO SUPPORT ANY SUCH THIRD-PARTY MATERIALS AND ALL RISKS RELATED TO THIRD-PARTY MATERIALS ARE YOUR RESPONSIBILITY. PLEASE ALSO REVIEW THE JUMPCLOUD TOS.

export users and password expiration date

dariovernelli
Novitiate III

Hi everybody,

I'd like to create a script using the Get-JCUser command to export all users with password_expiration_date minor than XX days or, maybe, with password_expiration_date - today() < XX days.

May I have some help from you ?

Thanks in advance,

Dario 

 

2 REPLIES 2

urvashi
Community Manager Community Manager
Community Manager

Hi @dariovernelli give me a day or two to try and put this together 🙂

yabagay
Novitiate II

Hello @dariovernelli ,

I hope it works for you.

Connect-JCOnline YourAPI
# Put a csv with users in C:\Temp\users.csv   Column name should be "username"
$csvPath = "C:\Temp\users.csv"
$exportedUsers = @()
$users = Import-Csv -Path $csvPath

foreach ($user in $users) {
    $displayName = $user.username
    Write-Host "Username: $displayName"
    
    # Get the password_date
    $passwordDate = Get-JCUser $displayName | Select-Object -ExpandProperty password_date
    
    # Convert the date to the appropriate format
    $passwordDateTime = [DateTime]::ParseExact($passwordDate, "yyyy-MM-ddTHH:mm:ss.fffZ", [System.Globalization.CultureInfo]::InvariantCulture)
    
    # Check the password change date
    $daysSincePasswordChange = (Get-Date) - $passwordDateTime
    
    # If the password change date is more than 100 days ago
    if ($daysSincePasswordChange.TotalDays -gt 100) {
        Write-Host "The user has to change your password."
        $exportedUsers += New-Object PSObject -Property @{
            "Username" = $displayName
            "Password Date" = $passwordDate
            "Password Status" = "The user has to change your password"
        }
    } else {
        Write-Host "There is no problem."
        $exportedUsers += New-Object PSObject -Property @{
            "Username" = $displayName
            "Password Date" = $passwordDate
            "Password Status" = "There is no problem"
        }
    }
}

# Export the results
$exportedUsers | Export-Csv -Path "C:\Temp\exported_users.csv" -NoTypeInformation
You Might Like

New to the site? Take a look at these additional resources:

Community created scripts:

Our new Radical Admin blog:

Keep up with Product News:

Read our community guidelines

Ready to join us? You can register here.