I thought I was being so smart, I decided to create a couple of functions and add them to my admin module so I could connect to my vCenter server so I could use my PowerCLI and to my Domain Controller so I can us my Quest snapins. But, when I run the command, I get connected but it doesn't stay connected at the prompt and the snapins don't stay loaded. I know I an get this done using my $profile, but I would rather have it only connect when I run a command. How do I make this work and stay working? I am pretty sure this is a scope issue
function Connect-ADVsi{
Param(
[string]$User = 'dom\dadmin',
[System.Security.SecureString]$PWord = (ConvertTo-SecureString –String "!password@" –AsPlainText -Force)
)
Add-PSSnapin Quest.ActiveRoles.ADManagement
$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User,$PWord
Connect-QADService -Service 'dc.dom.com' -Credential $Credential
}
I can kind of get it to work if I run it like this:
$test = Connect-ADVsi
Get-QADUser dadmin -connection $test
But if I just run Get-QADUser dadmin,
I get this:
Get-QADUser : The specified domain either does not exist or could not be contacted.
At line:1 char:1
+ Get-QADUser diverso
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetUserCmdlet
And this how I would like it to work, Get-QADUser dadmin, after I make a connection.