# Get information via Poweshell and Icinga Director API

**URL:** <https://community.icinga.com/t/get-information-via-poweshell-and-icinga-director-api/3141>\
**Category:** Automation & Infrastructure\
**Created:** [January 6, 2020, 6:45pm UTC](https://community.icinga.com/t/get-information-via-poweshell-and-icinga-director-api/3141 "2020-01-06T18:45:07Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![lukas](https://community.icinga.com/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@lukas](https://community.icinga.com/u/lukas)\
**Post date:** [January 9, 2020, 9:43am UTC](https://community.icinga.com/t/get-information-via-poweshell-and-icinga-director-api/3141/8 "2020-01-09T09:43:27Z")

</div>

> [@lukas](#):
>
> #Enable TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Thanks for your help, that’s what it was.

Solution:  
I created a user under IcingaWeb2 → configuration → authentication → user → "Create new user

After that I created a new role under IcingaWeb2 → configuration → authentication → Rollen→ “Create new role” and in the module “director” I added the rights “General Module Access” and “director/\*”. I added the user “user” to the role.

This gave me a correctly configured user for working with the Icinga Director API.

Then I wrote a script that creates the BasicAuthToken so that I can use it in the API script and the username and password are not visible in the API script.

> #Step 0. Set User and Password  
> $username = “user”  
> $password = “pass”
> 
> #Step 1. Create a username:password pair  
> $credPair = “$($username):$($password)”
> 
> #Step 2. Encode the pair to Base64 string  
> $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
> 
> #Step 3. Write.Output BasicAuth String  
> Write-Output $encodedCredentials

Now that I have a working user I have built a simple script for testing, it looks like this:

> #Enable TLS 1.2 - Is disabled by default  
> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
> 
> $headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
> 
> $headers.Add(“Accept”, “application/json”)
> 
> $headers.Add(“Authorization”, “Basic PasteBasicAuthStringhere”)
> 
> $response = Invoke-RestMethod ‘[https://icingaserver.here.local/icingaweb2/director/host?name=CLIENT01.here.local](https://icingaserver.here.local/icingaweb2/director/host?name=CLIENT01.here.local)’ -Method ‘GET’ -Headers $headers
> 
> $response | ConvertTo-Json

---

_[View the full topic](https://community.icinga.com/t/get-information-via-poweshell-and-icinga-director-api/3141)._
