Quantcast
Viewing all articles
Browse latest Browse all 19214

How do I store credentials in my powershell session without re-entering?

So I am running a function and one of the commands requires the users to have a mailbox in the forest.  I am running test-owaconnectivity, and when I'm running it against individual servers instead of the array, I have to enter my creds in the env to test.  That part i got figured out, problem is how do I get the creds stored so that when the commands reload or the function is called, the creds are still stored in the current pwshell window.  My example is below"

Function owa{
$Serverlist = Get-ClientAccessArray | ?{$_.members -like $env:computername} | %{$_.members} | %{$_.name}
$creds = Get-Credential
Foreach ($Server in $Serverlist) {
$ArrayOWA = Test-OWAConnectivity -URL:https://$Server/owa -TrustAnySslCert:$true -MailboxCredential $creds
if ($Arrayowa.Result.value.tostring() -like "*Failure*") {
Write-Host -ForegroundColor:DarkGray "$server " -NoNewline
Write-Host -ForegroundColor:DarkGray "Failure " -NoNewline
Write-Host -ForegroundColor:Red "OWA Connectivity " $ArrayOWA.url $Arrayowa.scenario $Arrayowa.Result.value.tostring() $line.error "!";
}# If Failure
else {
Write-Host -ForegroundColor:DarkGray "$server " -NoNewline
Write-Host -ForegroundColor:Cyan "OWA Connectivity " $Arrayowa.url -NoNewline
Write-Host -ForegroundColor:Cyan " Result = " -NoNewline 
Write-Host -ForegroundColor:Cyan $ArrayOWA.scenario $Arrayowa.result "Latency" $Arrayowa.latencyinmillisecondsstring 
}#If success
Write-Host " "
}
}

After the command runs the script is reloaded of course, but I want the creds to still be stored in the session.  So that $cred is able to pull them automatically, any thoughts?

Cheers.



JCtech1123, Cheers


Viewing all articles
Browse latest Browse all 19214

Trending Articles