Skip to content
Permalink
Browse files

Update from Forestry.io

Sheldon Hull updated content/docs/powershell.md
  • Loading branch information...
sheldonhull authored and Forestry.io committed Jun 20, 2019
1 parent d33700f commit e4739a10f02efe4a6759f74a5a9cd28ef7c7aedb
Showing with 21 additions and 0 deletions.
  1. +21 −0 content/docs/powershell.md
@@ -130,6 +130,27 @@ $UserName = $cred.GetNetworkCredential().UserName #Note that this could be an
$AccessKey = $cred.GetNetworkCredential().Password
```

### Using Basic Authorization With REST

When leveraging some api methods you need to encode the header with basic authentication to allow authenticated requests. This is how you can do that in a script without having to embed the credentials directly, leveraging `BetterCredentials` as well.

```powershell
#seems to work for both version 5.1 and 6.1
param(
$Uri = ''
)
Import-Module BetterCredentials
$cred = Find-Credential 'mycredentialname'
$AccessId = $cred.GetNetworkCredential().UserName
$AccessKey = $cred.GetNetworkCredential().Password
$Headers = @{
Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes( ('{0}:{1}' -f $AccessId, $AccessKey) ))
}
$results = Invoke-RestMethod -Uri $Uri -Header $Headers
$results
```

## Load Functions from a Folder

0 comments on commit e4739a1

Please sign in to comment.
You can’t perform that action at this time.