I like to wrap my login scripts into functions. I'm having a strange result with Active Roles attempting to connect the AR Proxy.
##ActiveRoles
function Login-QADService{
 param(
 [string]$passwordfile = "$([Environment]::GetFolderPath("MyDocuments"))\domainpassword.txt",
 [string]$username = 'DOMAIN\admin',
 [string]$service = 'ARServerService'
 )
 #Encrypt Password
 if(-not $(Test-Path -Path $passwordfile)){(get-credential).password | ConvertFrom-SecureString | set-content $passwordfile}
$password = Get-Content $passwordfile | ConvertTo-SecureString 
 $credential = New-Object System.Management.Automation.PsCredential("$username",$password)
 Connect-QADService -Proxy -Service $service -Credential $credential
}
If I try to run the function, it connects, but it's like it isn't using the credentials in the function. I know this because I have an 'regular' and 'admin' account and the regular account only has access to a single domain. I seem to be only getting the data for the single domain.
If I run the commands within the function I connect with my admin creds and data is returned as expected from all domains.
Can anyone see something wrong with my script?
 
				 
		 
					 
							