Closed cars closed 8 years ago
@cars I should have tried this before commenting on the previous PR. When I have an existing session, Import-VIRole makes use of it:
H:\> Connect-VIServer vcsa
Name Port User
---- ---- ----
vcsa 443 LAB\rn7284
H:\> C:\Users\rnelson0\Documents\vCenter-roles\Import-VIRole.ps1
H:\> Import-VIRole -Name Test -RoleFile C:\Users\rnelson0\Documents\vCenter-roles\Import-VIRole.ps1 -vCenter vcsa
Role already exists.
At C:\Users\rnelson0\Documents\vCenter-roles\Import-VIRole.ps1:106 char:13
+ Throw 'Role already exists.'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Role already exists.:String) [], RuntimeException
+ FullyQualifiedErrorId : Role already exists.
In what circumstances are you not seeing it take advantage of the existing connection, or otherwise cause an interruption?
Thanks!
I was seeing myself get prompted for credentials when I was using this from a Pester/Vester test.... Let me go look at it again.....
Is there a test that is calling Disconnect-VIServer
somewhere in there? By passing the Session
value to Connect-VIServer
, it should try and use the existing one. The only caveat I see is that you must use the same name you used originally. I.e. Connect-VIserver vcsa.example.com
followed by Import-VIRole ... -vCenter vcsa
will prompt for credentials as vcsa
and vcsa.example.com
are treated as different VIServers.
Yeah I think that that's what happened. I was switching between vcenters and not being consistent with what hostname I was using.
Cool, glad we could figure it out. Thanks for using this!
Trying to leverage this for the Vester project. Vester assumes there's already a vCenter connection. Modify Import-VIRole to try to use that connection rather than re-running connect-viserver which prompts for creds...