Summary
The below script provides a basic example for the usage of N2W API with PowerShell.
Description
The below script provides a basic example for the usage of N2W API with PowerShell.
Copy the text below into a script.ps1 file. Please note that the text in brackets, [], should be replaced with your system’s relevant parameters:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$ApiKey = "[Enter_your_API_Key_here]"
$your_cpm_address = "https://[enter_you_N2W_address]"
$tokenobtainurl = -join($your_cpm_address,"/api/token/obtain/api_key/")
$path_to_file = "[Insert_full_path_to_where_you_want_to_print_the_users_list_to\users.txt]"
#The below command stores the access key and refresh key received in the response from CPM
$Response = Invoke-WebRequest -Uri $tokenobtainurl -Method "POST" -Headers @{"Authorization" = "Bearer $NO_AUTH" } -ContentType "application/json" -Body "{`"api_key`":`"$ApiKey`"}" | ConvertFrom-Json
Write-Host "Your Access key is:" $Response.access
Write-Host "Your Refresh key is:" $Response.refresh
#Building the Authorization header
$Authorization = -join("Bearer ", $Response.access)
Write-Host "The Authorization Header is:" $Authorization
#Example below receives the list of users and stores them into a file on your PC
$userspath = -join($your_cpm_address,"/api/users/")
Invoke-WebRequest -Uri $userspath -Method "GET" -Headers @{"Authorization"="$Authorization"; "Accept"="application/json; version=1.0" } -ContentType "application/json" -OutFile $path_to_file | ConvertFrom-Json
Execute the script.
For full API documentation, please refer to CLI guide and software download for N2WS v4.4.0
CLI guide and software download for N2W v4.4.0
Confirmation Steps
Following executing the script, the file defined will include the list of N2W server users.
Comments
0 comments
Please sign in to leave a comment.