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.

Manager Username — Making use of calculated fields in PowerShell

jworkman
JumpCloud Employee
JumpCloud Employee

Several folks have asked how might a JumpCloud customer report on all their users and also display those user's assigned manager. When running `Get-JCUser`, the cmdlet returns all JumpCloud users and their details from our API. The manager field contains an ID which refers to the ID of the JumpCloud user (the manager of a given user). 

In order to get details about this managerID the `Get-JCUser` function can be used to search users by ID. In just three lines of PowerShell code, we can produce a report showing all JumpCloud users and a calculated field showing those user's assigned manager username.

First let's get some data about all our users:

 

$users = Get-JCUser

 

 Here, the `$users` variable will store all data about our JumpCloud users including the managerID field.

We can display all fields (or just specific fields) using the Select-Object cmdlet

Display All Fields

 

$users | Select-Object *

 

 Display just the username, mangerID fields:

 

$users | Select-Object username, manager

 

users shown with their assigned ManagerIDusers shown with their assigned ManagerID

Again, we know that the managerID field is just a userID and in order to lookup that value we just need to run the ID through `Get-JCUser`. To do that we can make use of calculated properties which are nothing more than values calculated at time of execution. 

 

$users | Select-Object username, @{ Name = 'ManagerUsername'; Expression = { (Get-JCUser -userid $_.manager).Username } }

 

manager matched lookupmanager matched lookup

Here we see that the usernames for the managers are displayed in the second column. The code above simply calculates the column named "managerUsername" with the value in the expression, which in this case, is the lookup per user, returning only the username of the matched managerID.

Putting it all together we can export everything as a CSV. 

 

# Get All Users
$users = Get-JCUser
# Store all user properties + calculated "managerUsername" in a new variable called $list
$list = $users | Select-Object *, @{ Name = 'ManagerUsername'; Expression = { (Get-JCUser -userid $_.manager).Username } }
# Export $list as a csv
$list | ConvertTo-Csv | Out-File ./userReport.csv

 

And with just three lines of code, you can produce a report containing all user properties and the new calculated property to lookup manager username. Hopefully this is helpful for folks looking to get more out of their PowerShell reports or automations in general.

CSV reportCSV report 

0 REPLIES 0