I could use a bit of help on a script I am writing. I normally code in Python and it has the ability to unpack data into multiple variables. For example (a, b, c) = (1, 2, 3) where a =1, b=2,c=3 and can now be manipulated independently. Is there a similar ability in Powershell?
Here is a sample of my script. I import a csv file that has three columns of data with the following headings(labels) Box, Username, Password. I want to unpack each column into its on variable so that I can plug them in to the Invoke-VMscript cmdlet.
Well I solved my own problem so I thought I would share my solution in case someone has the same issue. I realized that when I import the file in to my $file variable that it is an object that has the properties of the three column labels in my csv, Box, Username, Password. This allowed me to reference them inside of my loop by unpacking/ assigning each label in $line into a specific variable.
$file = Import-Csv user_pass.csv
foreach ($line in $file){
$box = $line.Box
$username = $line.Username
$Password = $line.Password
Invoke-VMScript -vm $box -ScriptText {systeminfo.exe | Select-String -pattern 'Os Name','Os Version'} -GuestUser $username -GuestPassword $password | out-file $box
Invoke-VMScript -vm $box -ScriptText {wmic product} -GuestUser $username -GuestPassword $password | out-file -Append $box
I Hope this helps someone else. Also if any of the pros out there have any wisdom to share it is totally welcome. Please excuse any incorrect references to Powershell nomenclature.