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 

 

1 ACCEPTED SOLUTION

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

View solution in original post

4 REPLIES 4

urvashi
Bronze I
Bronze I

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

dariovernelli
Novitiate III

Hi Yabagay,

sorry for my late response. It works well on Windows OS, many thanks.

I have only changed the line 15 to:

$passwordDateTime = [DateTime]::ParseExact($passwordDate, "MM/dd/yyyy HH:mm:ss", [System.Globalization.CultureInfo]::InvariantCulture)
 
In this way the script can work on my MacOs.
Many thanks,
Dario

 

 

yabagay
Novitiate II

Hello Dario,

Thank you for updating it. 

Glad to hear it. 

Yusuf

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.