I have a script which invokes a session on remote computer and run a script.
$pw = convertto-securestring -AsPlainText -Force -String '$(PWD_vSphere_AdminUser)'
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist ".\Administrator",$pw
Invoke-Command -Credential $Cred -ComputerName 'testcomputer' -FilePath "./addvm.ps1"
This works fine. Now I have to run it on multiple computers. I want to read -ComputerName values from a tfvars file (json format). where name = "testcomputer" occurring multiple times. I want to read this "name" value from tfvars file (json format) and run my script for each "name" value.
{
"vm": [
{
"testcomputer": [
{
"memory": "4096",
"name": "testcomputer",
"time_zone": "020"
}
],
"testcomputer1": [
{
"memory": "4096",
"name": "testcomputer1",
"time_zone": "020"
}
],
"testcomputer2": [
{
"memory": "4096",
"name": "testcomputer2",
"time_zone": "020"
}
]
}
]
}
I have read this Powershell retrieving a variable from a text file but that dosen`t solve much about occurrence.
Invoke-Command