I have sample code as below:
$IP=@("IP1","IP2","IP3", "IP4" , "IP5")
$Hostname=@("Host1","Host2","Host3","HOST4", "HOST5")
$data = Read-Host -Prompt 'Please enter the data.'
if ($data -match 'zone1') {
$Unity=$IP[0]
$show=$hostname[0]
} elseif ($data -match 'site2'){
$Unity=$IP[1]
$show=$hostname[1]
} elseif ($data -match 'unit5'){
$Unity=$IP[2]
$show=$hostname[2]
} elseif ($data -match 'ALL DC'){
$Unity=$IP
$show=$hostname
}
foreach ($u in $Unity){
echo "This is my IP" $u
echo "This is my hostname" $show
}
Codework fine for all the options except ALL DC. I want to run some command which uses hostname and Ip.
Desired Output when ALL DC is input by the user is
This is my IP IP1 This is my hostname Host1 This is my IP IP2 This is my hostname Host2 This is my IP IP3 This is my hostname Host3 This is my IP IP4 This is my hostname Host4 This is my IP IP5 This is my hostname Host5
$data
before assigning it.$show = $hostname
. What exactly do you want the output to be? Add that to your question!