Ok,
I finally figured this out. I know itâs not the best method, but I prefer this than having the wording âplain textâ Hereâs what I did in case someone needs to do the same.
I read that API tokens do not go well as a securestring. Here are some references:
https://jamesone111.wordpress.com/2020/04/10/transformers-for-powershell-parameters-which-take-secrets/, and https://github.com/Azure/azure-powershell/issues/25533.
So in order to get past this, I needed to create another variable as show below:
$testapi1 = [pscredential]::new(âtokenâ,$yourtoken)
Youâre basically adding the pscredential above like youâre going to setup a username, but you put something like âtokenâ or any wording as a placeholder for the username, then put the token in.
Then after you define the header you do something like this: $testheader.add(fog-user-tokenâ,$testapi1.GetNetworkCredential().password)
Again itâs not the best method, but I also read a way when you do read-host -aseecurestring and save your api there as a variable, you can dispose that variable so it doesnât stay in memory.
$test.disposeof
If someone has any better ideas, please let me know as Iâm always on here learning new things and want to share as well. This basically can be closed out.