Hi Allan,
You could try using a PowerShell Runspace
You can refer the below link for runsapce:
Runspace : https://devblogs.microsoft.com/scripting/beginning-use-of-powershell-runspaces-part-1/
I would recommend you to use the module “POSHRSJob”, it is available on PowerShell gallery. (This module internally uses runspace to run multiple jobs)
So you can do something like this
Install the module, this is a onetime install
Install-Module -Name POSHRSJob
Put this in your PowerShell Profile
Import-Module POSHRSJob
$job = Start-RSJob -ScriptBlock{
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$credsobj = New-Object System.Management.Automation.PSCredential ("username", $password)
Import-Module -Name Cisco.UCSCentral
Connect-UcsCentral <<IP>> -Credential $credsobj -NotDefault
}
Exit PowerShell session and start new session
Run UCS Central cmdlets using the returned connection
Import-Module -Name Cisco.UCSCentral
$connection = $job | Receive-RSJob
Import-Module -Name Cisco.UCSCentral
Get-UCSCentralOrg -UcsCentral $connection
To remove the connection
Disconnect-UcsCentral -UcsCentral $connection