I have been working on wrapping a working PowerCLI script with a GUI so the work of bulk VM creation can be handed off to another group of people. The script and what I have run into thus far can be seen here: Datastore and VMHost vs Cluster
Both the GUI and original script are working, I am just trying to marry the two with the least amount of overhead. The issue I am currently working through is the GUI script returns the information on the VMs to be created in an array table, like so:
My concern is around the best means to pass this array to the PowerCLI script, so that I am not recreating the Connect-VIServer connection (to multiple servers) multiple times. I am just curious if exporting the table to a csv is my best/only option. Can an entire array be passed to the script on calling? Is any level of inter-script communication supported as in other languages, or is there a supported method for opening the connection in one script and then running another script within the scope of that connection?
If I am overthinking it, please feel free to say so
A connection made with Connect-VIServer receives a SessionId.
You can use this SessionId to do a new Connect-VIServer (with the Session parameter).
And yes, you can pass an array as an argument to a function,
As an example
testarray.ps1
param(
[int[]]$array
)
$array.Count
test
$t = 1,2,3,4
.\testarray.ps1 $t
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
A connection made with Connect-VIServer receives a SessionId.
You can use this SessionId to do a new Connect-VIServer (with the Session parameter).
And yes, you can pass an array as an argument to a function,
As an example
testarray.ps1
param(
[int[]]$array
)
$array.Count
test
$t = 1,2,3,4
.\testarray.ps1 $t
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, I will take a look at these. I confirmed I can pass the SessionID from script to script; will play around with passing multiple IDs from multiple connections.
Just take note that there is a session timeout.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, I was thinking about this as well. As I am making a connection to multiple vCenter Servers, the prospect of grabbing all of the Session IDs and passing those to the second is making less and less sense. Also, while your example of passing the array worked great (will store that for future use!) as this array is going to be a large 2D - 15 or 16 column - array, I think I am over-complicating it. Best just to export to csv and then import, after all. Nevertheless, thanks for all the advice.
If you are not starting a new PowerShell process, but instead would be using jobs, you could use a reference variable.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference