<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PowerCLI: Easy vSwitch &amp; PortGroup Setup</title>
	<atom:link href="http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/</link>
	<description>Virtually everything is poshable</description>
	<lastBuildDate>Sat, 11 Feb 2012 14:14:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Rusty</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-7010</link>
		<dc:creator>Rusty</dc:creator>
		<pubDate>Mon, 11 Jul 2011 04:55:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-7010</guid>
		<description>Script works a treat, but doesn&#039;t add the nics.</description>
		<content:encoded><![CDATA[<p>Script works a treat, but doesn&#8217;t add the nics.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dorothy</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-5359</link>
		<dc:creator>Dorothy</dc:creator>
		<pubDate>Fri, 04 Mar 2011 17:03:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-5359</guid>
		<description>Hi Mike,

I&#039;m using your version of the script. It&#039;s working really well for me and I&#039;ve made my own additions for our environment. The only piece I can&#039;t get to work is the vmkernel creation (I had to remove this piece to test the rest). 

If I don&#039;t modify the script, I get this error:
[vSphere PowerCLI] &gt; .\copyportgroups_tmp.ps1
Unexpected token &#039;What&#039; in expression or statement.
At D:\copyportgroups_tmp.ps1:39 char:28
+ $MotionIP = Read-Host &quot;What &lt;&lt;&lt; .\copyportgroups_tmp.ps1
Unexpected token &#039;Creating&#039; in expression or statement.
At D:\copyportgroups_tmp.ps1:43 char:21
+ Write-Host &quot;Creating &lt;&lt;&lt;&lt;  $($vmk) on $($NewHost).&quot;
    + CategoryInfo          : ParserError: (Creating:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

Thanks for the help.</description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>I&#8217;m using your version of the script. It&#8217;s working really well for me and I&#8217;ve made my own additions for our environment. The only piece I can&#8217;t get to work is the vmkernel creation (I had to remove this piece to test the rest). </p>
<p>If I don&#8217;t modify the script, I get this error:<br />
[vSphere PowerCLI] > .\copyportgroups_tmp.ps1<br />
Unexpected token &#8216;What&#8217; in expression or statement.<br />
At D:\copyportgroups_tmp.ps1:39 char:28<br />
+ $MotionIP = Read-Host &#8220;What <<< .\copyportgroups_tmp.ps1<br />
Unexpected token &#8216;Creating&#8217; in expression or statement.<br />
At D:\copyportgroups_tmp.ps1:43 char:21<br />
+ Write-Host &#8220;Creating <<<<  $($vmk) on $($NewHost).&#8221;<br />
    + CategoryInfo          : ParserError: (Creating:String) [], ParseException<br />
    + FullyQualifiedErrorId : UnexpectedToken</p>
<p>Thanks for the help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PowerCLI: vProfiles &#171; Virtu-Al</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-5116</link>
		<dc:creator>PowerCLI: vProfiles &#171; Virtu-Al</dc:creator>
		<pubDate>Sat, 19 Feb 2011 15:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-5116</guid>
		<description>[...] my recent post, Easy vSwitch &amp; PortGroup Setup I thought I would give PrimalForms a go and create a quick GUI, PrimalForms is a great app from [...]</description>
		<content:encoded><![CDATA[<p>[...] my recent post, Easy vSwitch &amp; PortGroup Setup I thought I would give PrimalForms a go and create a quick GUI, PrimalForms is a great app from [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ajay Nabh</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-4921</link>
		<dc:creator>Ajay Nabh</dc:creator>
		<pubDate>Wed, 02 Feb 2011 21:37:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-4921</guid>
		<description>Thanks Mike

script did prompt me for VI server and source/destination and it generate this error after accepting the infomation. I will try again as you mentioned. thanks heaps
Ajay</description>
		<content:encoded><![CDATA[<p>Thanks Mike</p>
<p>script did prompt me for VI server and source/destination and it generate this error after accepting the infomation. I will try again as you mentioned. thanks heaps<br />
Ajay</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-4912</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 02 Feb 2011 14:22:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-4912</guid>
		<description>Hi Ajay. 

That has nothing to do with ESXi or ESX. That command is trying to connect to your vCenter server.

In the command:

$VISRV = Connect-VIServer # or ask (Read-Host “Please enter the name of your VI SERVER”)

the &quot;#&quot; is a commentor, meaning everything after that is ignored. So, put the FQDN of your vCenter server just before the &quot;#&quot; or remove the &quot;# or ask&quot; part and it will ask when you run the script.

Hope that helps...

Mike</description>
		<content:encoded><![CDATA[<p>Hi Ajay. </p>
<p>That has nothing to do with ESXi or ESX. That command is trying to connect to your vCenter server.</p>
<p>In the command:</p>
<p>$VISRV = Connect-VIServer # or ask (Read-Host “Please enter the name of your VI SERVER”)</p>
<p>the &#8220;#&#8221; is a commentor, meaning everything after that is ignored. So, put the FQDN of your vCenter server just before the &#8220;#&#8221; or remove the &#8220;# or ask&#8221; part and it will ask when you run the script.</p>
<p>Hope that helps&#8230;</p>
<p>Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ajay Nabh</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-4884</link>
		<dc:creator>Ajay Nabh</dc:creator>
		<pubDate>Mon, 31 Jan 2011 23:05:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-4884</guid>
		<description>Hi Guys

I am trying this script from 1 esxi to another esxi and both are 4.0 U2 and geting this error!! help if you guys can
Connect-VIServer : A positional parameter cannot be found that accepts argument
 &#039;$null&#039;.
At line:1 char:26</description>
		<content:encoded><![CDATA[<p>Hi Guys</p>
<p>I am trying this script from 1 esxi to another esxi and both are 4.0 U2 and geting this error!! help if you guys can<br />
Connect-VIServer : A positional parameter cannot be found that accepts argument<br />
 &#8216;$null&#8217;.<br />
At line:1 char:26</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PowerCLI: Easy NFS datastore setup &#171; ICT-Freak.nl</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-4384</link>
		<dc:creator>PowerCLI: Easy NFS datastore setup &#171; ICT-Freak.nl</dc:creator>
		<pubDate>Mon, 03 Jan 2011 07:36:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-4384</guid>
		<description>[...] so let’s start with a new PowerCLI post. This post is
inspired by the blog post of @alanrenouf: PowerCLI easy vswitch
portgroup setup. I love the whole idea of taking a good working
config from a vSphere host and use it on a fresh [...]</description>
		<content:encoded><![CDATA[<p>[...] so let’s start with a new PowerCLI post. This post is<br />
inspired by the blog post of @alanrenouf: PowerCLI easy vswitch<br />
portgroup setup. I love the whole idea of taking a good working<br />
config from a vSphere host and use it on a fresh [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-3211</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 03 Nov 2010 15:20:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-3211</guid>
		<description>I have worked more on &quot;my&quot; version of the script. It now looks at one host and configures another host to have the same vSwitches with portgroups and VLANs. It does ESXi and vmk interfaces and will ask you which of the vSwitches on the existing host you want to &quot;copy&quot; to the new host. This was helpful for me where I was occasionally changing a host from one cluster to another and I wanted to leave one vSwitch alone (this might be specific to my environment). My vMotion vmk interfaces are always on vSwitch0, thus the part where I ask what the vMotion IP is if the current vSwitch is vSwithc0. Sorry about that, but that&#039;s the way it works for me.

Use this in a testing area first, or use it for ideas. Full credit to Al as this is still mainly his work that I merely tweaked. I am NOT a programmer and someone will likely hate the way I do things. No worries.

function AskEm {
	$caption = &quot;Select:&quot;;
	$message = &quot;Add item $element to the new list?&quot;;
	$yes = new-Object System.Management.Automation.Host.ChoiceDescription &quot;&amp;Yes&quot;,&quot;help&quot;;
	$no = new-Object System.Management.Automation.Host.ChoiceDescription &quot;&amp;No&quot;,&quot;help&quot;;
	$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no);
	$answer = $host.ui.PromptForChoice($caption,$message,$choices,0)
	switch ($answer){
    0 {$Global:NewList += @($element)}
    1 {continue}	
	}
}
# initialize a variable
$Global:NewList = $null

$VISRV = Connect-VIServer  # or ask (Read-Host &quot;Please enter the name of your VI SERVER&quot;)
$BASEHost = Get-VMHost -Name (Read-Host &quot;Please enter the name of your existing server as seen in the VI Client:&quot;)
$NEWHost = Get-VMHost -Name (Read-Host &quot;Please enter the name of the server to configure as seen in the VI Client:&quot;)

# get the switches for the base host
$MySwitches = $BASEHost &#124;Get-VirtualSwitch

# ask the user to select what switches to look at and copy
foreach ($element in $MySwitches) {
	Askem
}


#go thru each switch selected above  
foreach ($switch in $NewList) {
	# check to see if the switch already exists on the new host - if so don&#039;t create it.
   If (($NEWHost &#124;Get-VirtualSwitch -Name $switch.Name -ErrorAction SilentlyContinue)-eq $null){
   		# if not, create it...
       Write-Host &quot;Creating Virtual Switch $($switch.Name) on $($NEWHost).&quot;
       $NewSwitch = $NEWHost &#124;New-VirtualSwitch -Name $switch.Name -NumPorts $switch.NumPorts -Mtu $switch.Mtu
	}
	Else {Write-Host &quot;Vswitch $($switch.name) already exists on $($NEWHost). Checking port groups on this switch.&quot;}
			
	If ($switch.Name -eq &quot;vSwitch0&quot;) {
			$MotionIP = Read-Host &quot;What is the IP for the VMotion Network?&quot;
			$MyVMKs = $BASEHost	 &#124; Get-VMHostNetworkAdapter -VMKernel
			foreach ($vmk in $MyVMKs) {
				if (($NEWHost &#124; Get-VMHostNetworkAdapter -VMKernel).devicename -ne $vmk.DeviceName) {
				Write-Host &quot;Creating $($vmk) on $($NewHost).&quot;
				$vmkpg = Get-VirtualPortGroup -Name $vmk.portgroupname -VMHost $BASEhost
				if ($vmk.PortGroupName -eq &quot;VMkernel-VMotion&quot;) {
					$NewVMK = $NEWHost &#124; New-VMHostNetworkAdapter -PortGroup $vmk.portgroupname -SubnetMask $vmk.subnetmask -VMotionEnabled $vmk.vmotionenabled -VirtualSwitch $vmkpg.virtualswitchname -IP $MotionIP}
				else {$NewVMK = $NEWHost &#124; New-VMHostNetworkAdapter -PortGroup $vmk.portgroupname -SubnetMask $vmk.subnetmask -VMotionEnabled $vmk.vmotionenabled -VirtualSwitch $vmkpg.virtualswitchname}
				get-virtualportgroup -VMHost $NEWHost -Name $vmk.portgroupname &#124; Set-VirtualPortGroup -VLanId $vmkpg.vlanid
				}
			}
		}
	Else {
		$MyPGs = $switch &#124; Get-VirtualPortGroup
		foreach ($Pg in $MyPGs) {
			If (($NEWHost &#124;Get-VirtualPortGroup -Name $PG.Name-ErrorAction SilentlyContinue)-eq $null){
			Write-Host &quot;Creating Portgroup $($PG.Name) on $($switch)&quot;
			$NewPortGroup = $NEWHost &#124;Get-VirtualSwitch -Name $switch &#124;New-VirtualPortGroup -Name $PG.Name -VLanId $PG.VLanID
			}
		}
	}
  	
}

Hope this helps...</description>
		<content:encoded><![CDATA[<p>I have worked more on &#8220;my&#8221; version of the script. It now looks at one host and configures another host to have the same vSwitches with portgroups and VLANs. It does ESXi and vmk interfaces and will ask you which of the vSwitches on the existing host you want to &#8220;copy&#8221; to the new host. This was helpful for me where I was occasionally changing a host from one cluster to another and I wanted to leave one vSwitch alone (this might be specific to my environment). My vMotion vmk interfaces are always on vSwitch0, thus the part where I ask what the vMotion IP is if the current vSwitch is vSwithc0. Sorry about that, but that&#8217;s the way it works for me.</p>
<p>Use this in a testing area first, or use it for ideas. Full credit to Al as this is still mainly his work that I merely tweaked. I am NOT a programmer and someone will likely hate the way I do things. No worries.</p>
<p>function AskEm {<br />
	$caption = &#8220;Select:&#8221;;<br />
	$message = &#8220;Add item $element to the new list?&#8221;;<br />
	$yes = new-Object System.Management.Automation.Host.ChoiceDescription &#8220;&amp;Yes&#8221;,&#8221;help&#8221;;<br />
	$no = new-Object System.Management.Automation.Host.ChoiceDescription &#8220;&amp;No&#8221;,&#8221;help&#8221;;<br />
	$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no);<br />
	$answer = $host.ui.PromptForChoice($caption,$message,$choices,0)<br />
	switch ($answer){<br />
    0 {$Global:NewList += @($element)}<br />
    1 {continue}<br />
	}<br />
}<br />
# initialize a variable<br />
$Global:NewList = $null</p>
<p>$VISRV = Connect-VIServer  # or ask (Read-Host &#8220;Please enter the name of your VI SERVER&#8221;)<br />
$BASEHost = Get-VMHost -Name (Read-Host &#8220;Please enter the name of your existing server as seen in the VI Client:&#8221;)<br />
$NEWHost = Get-VMHost -Name (Read-Host &#8220;Please enter the name of the server to configure as seen in the VI Client:&#8221;)</p>
<p># get the switches for the base host<br />
$MySwitches = $BASEHost |Get-VirtualSwitch</p>
<p># ask the user to select what switches to look at and copy<br />
foreach ($element in $MySwitches) {<br />
	Askem<br />
}</p>
<p>#go thru each switch selected above<br />
foreach ($switch in $NewList) {<br />
	# check to see if the switch already exists on the new host &#8211; if so don&#8217;t create it.<br />
   If (($NEWHost |Get-VirtualSwitch -Name $switch.Name -ErrorAction SilentlyContinue)-eq $null){<br />
   		# if not, create it&#8230;<br />
       Write-Host &#8220;Creating Virtual Switch $($switch.Name) on $($NEWHost).&#8221;<br />
       $NewSwitch = $NEWHost |New-VirtualSwitch -Name $switch.Name -NumPorts $switch.NumPorts -Mtu $switch.Mtu<br />
	}<br />
	Else {Write-Host &#8220;Vswitch $($switch.name) already exists on $($NEWHost). Checking port groups on this switch.&#8221;}</p>
<p>	If ($switch.Name -eq &#8220;vSwitch0&#8243;) {<br />
			$MotionIP = Read-Host &#8220;What is the IP for the VMotion Network?&#8221;<br />
			$MyVMKs = $BASEHost	 | Get-VMHostNetworkAdapter -VMKernel<br />
			foreach ($vmk in $MyVMKs) {<br />
				if (($NEWHost | Get-VMHostNetworkAdapter -VMKernel).devicename -ne $vmk.DeviceName) {<br />
				Write-Host &#8220;Creating $($vmk) on $($NewHost).&#8221;<br />
				$vmkpg = Get-VirtualPortGroup -Name $vmk.portgroupname -VMHost $BASEhost<br />
				if ($vmk.PortGroupName -eq &#8220;VMkernel-VMotion&#8221;) {<br />
					$NewVMK = $NEWHost | New-VMHostNetworkAdapter -PortGroup $vmk.portgroupname -SubnetMask $vmk.subnetmask -VMotionEnabled $vmk.vmotionenabled -VirtualSwitch $vmkpg.virtualswitchname -IP $MotionIP}<br />
				else {$NewVMK = $NEWHost | New-VMHostNetworkAdapter -PortGroup $vmk.portgroupname -SubnetMask $vmk.subnetmask -VMotionEnabled $vmk.vmotionenabled -VirtualSwitch $vmkpg.virtualswitchname}<br />
				get-virtualportgroup -VMHost $NEWHost -Name $vmk.portgroupname | Set-VirtualPortGroup -VLanId $vmkpg.vlanid<br />
				}<br />
			}<br />
		}<br />
	Else {<br />
		$MyPGs = $switch | Get-VirtualPortGroup<br />
		foreach ($Pg in $MyPGs) {<br />
			If (($NEWHost |Get-VirtualPortGroup -Name $PG.Name-ErrorAction SilentlyContinue)-eq $null){<br />
			Write-Host &#8220;Creating Portgroup $($PG.Name) on $($switch)&#8221;<br />
			$NewPortGroup = $NEWHost |Get-VirtualSwitch -Name $switch |New-VirtualPortGroup -Name $PG.Name -VLanId $PG.VLanID<br />
			}<br />
		}<br />
	}</p>
<p>}</p>
<p>Hope this helps&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 10 Steps to Kick-Start Your VMware Automation with PowerCLI &#124; www.wiseinn.com</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-2880</link>
		<dc:creator>10 Steps to Kick-Start Your VMware Automation with PowerCLI &#124; www.wiseinn.com</dc:creator>
		<pubDate>Mon, 11 Oct 2010 21:59:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-2880</guid>
		<description>[...] PowerCLI community expert Alan Renouf has provided a simple alternative solution to this problem via his blog (rather than reproduce the script here, I recommend you take a look at his blog once you&#8217;ve [...]</description>
		<content:encoded><![CDATA[<p>[...] PowerCLI community expert Alan Renouf has provided a simple alternative solution to this problem via his blog (rather than reproduce the script here, I recommend you take a look at his blog once you&rsquo;ve [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/#comment-2486</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Fri, 09 Jul 2010 12:58:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.virtu-al.net/?p=731#comment-2486</guid>
		<description>I used it just the other day against an ESXi 4 host, but not without some issues. I was using a version I am sorta working on that tries to create the vswitches, add portgroups and VMkernel ports and adds vnics to the vswitches. It does this by looking at an existing host and making the new host just like the old one. Still not much of my work - mainly Al&#039;s.

The part ESXi didn&#039;t seem to like was the fact that the VMkernel ports are vmk0, vmk1, etc. instead of looking a bit like ESX portgroups. Still things to look at in &quot;my&quot; version before it is ready to use in Production.</description>
		<content:encoded><![CDATA[<p>I used it just the other day against an ESXi 4 host, but not without some issues. I was using a version I am sorta working on that tries to create the vswitches, add portgroups and VMkernel ports and adds vnics to the vswitches. It does this by looking at an existing host and making the new host just like the old one. Still not much of my work &#8211; mainly Al&#8217;s.</p>
<p>The part ESXi didn&#8217;t seem to like was the fact that the VMkernel ports are vmk0, vmk1, etc. instead of looking a bit like ESX portgroups. Still things to look at in &#8220;my&#8221; version before it is ready to use in Production.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

