VMware Cloud Community
mdangel1
Enthusiast
Enthusiast
Jump to solution

Create switches , but need to ask for input for switch name

Hello All,

I want to automate creating standard switches, but I want the scrip t to ask for input on the portgroup name and VLAN ID.

This is what I have so far

$MyHost = Read-Host "Enter Host name"
Read-Host -Prompt "Testing"
$standardswitch = Read-Host "Enter Switch Name"

New-VirtualSwitch -VMHost $MyHost -Name vSwitch1 -nic vmnic6,vmnic9

Get-VMHost $MyHost | Get-VirtualSwitch -Name $standardswitch | Get-SecurityPolicy | Set-SecurityPolicy -MacChanges $false | ForgedTransmits $False | AllowPromiscous $False

Get-VMHost $MyHost | Get-VirtualSwitch -name $standardswitch | New-VirtualPortGroup -Name portgroupname -VLanID 1234

Get-VMHost $MyHost | Get-VirtualSwitch -Name "vSwitch0" | Get-SecurityPolicy | Set-SecurityPolicy -MacChanges $false | ForgedTransmits $False | AllowPromiscous $False

Reply
0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can also use the Read-Host cmdlet for that.
Something like this

$MyHost = Read-Host "Enter Host name"
Read-Host -Prompt "Testing"
$standardswitch = Read-Host "Enter Switch Name"

New-VirtualSwitch -VMHost $MyHost -Name $standardswitch -nic vmnic6,vmnic9

Get-VMHost $MyHost | Get-VirtualSwitch -Name $standardswitch | Get-SecurityPolicy | Set-SecurityPolicy -MacChanges $false -ForgedTransmits $False -AllowPromiscous $False
$pgName = Read-Host "Portgroup name"
$vlanId = Read-Host "VlanId for portgroup $pgName"
Get-VMHost $MyHost | Get-VirtualSwitch -name $standardswitch | New-VirtualPortGroup -Name $pgName -VLanID $vlanId


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

LucD
Leadership
Leadership
Jump to solution

Yes, and it will also ask for the VlanId


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

You can also use the Read-Host cmdlet for that.
Something like this

$MyHost = Read-Host "Enter Host name"
Read-Host -Prompt "Testing"
$standardswitch = Read-Host "Enter Switch Name"

New-VirtualSwitch -VMHost $MyHost -Name $standardswitch -nic vmnic6,vmnic9

Get-VMHost $MyHost | Get-VirtualSwitch -Name $standardswitch | Get-SecurityPolicy | Set-SecurityPolicy -MacChanges $false -ForgedTransmits $False -AllowPromiscous $False
$pgName = Read-Host "Portgroup name"
$vlanId = Read-Host "VlanId for portgroup $pgName"
Get-VMHost $MyHost | Get-VirtualSwitch -name $standardswitch | New-VirtualPortGroup -Name $pgName -VLanID $vlanId


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mdangel1
Enthusiast
Enthusiast
Jump to solution

Thank you! apologies for the confusion, will this ask for portgroup and vlan id name?

Reply
0 Kudos
mdangel1
Enthusiast
Enthusiast
Jump to solution

sorry, I see the variable that it will ask for name. correct?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, and it will also ask for the VlanId


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mdangel1
Enthusiast
Enthusiast
Jump to solution

Thank you so very much!!!!!!!!!!!!!!!!

Reply
0 Kudos