Forum Discussion
FortyMegabytes
Nov 06, 2020Brass Contributor
Using Add-RdsAccount in a function
I want to use Add-RdsAccount in a function that's called by other scripts. But for the life of me, I cannot make work. The "Add-RdsAccount" call works and successfully authenticates, but *only* for...
BrianJones
Mar 11, 2021Copper Contributor
I was able to get the Add-RdsAccount command to work inside a class method (and the same should work inside a function) like this:
Class RdsClass {
[void] RdsConnect ([string]$DeploymentUrl, [PSCredential]$AzureCredential) {
Add-RdsAccount -DeploymentUrl $DeploymentUrl -Credential $AzureCredential
$Global:RdMgmtContext = (Get-Variable -Name RdMgmtContext).Value
$Global:AdalContext = (Get-Variable -Name AdalContext).Value
}
}
Then I am able to use:
[RdsClass]::New().RdsConnect($MyDeploymentUrl, $MyAzureCredentials)