<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andrew Morgan &#187; Powercli</title>
	<atom:link href="http://andrewmorgan.ie/tag/powercli/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewmorgan.ie</link>
	<description>Grumpy ramblings</description>
	<lastBuildDate>Fri, 30 Jun 2017 09:24:25 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0</generator>
	<item>
		<title>Unique portgroup fiddling with #Powercli.</title>
		<link>http://andrewmorgan.ie/2011/09/unique-portgroup-fiddling-with-powercli/</link>
		<comments>http://andrewmorgan.ie/2011/09/unique-portgroup-fiddling-with-powercli/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 12:16:11 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[PowerClI]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Powercli]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=691</guid>
		<description><![CDATA[As my peers seem to like to flout convention, particularly naming conventions. I was left with a strange automation challenge this week. with a new service coming online in my company, I had 12 vlan portgroups to add to over 30 ESXi machines. Simple you say, just pipe your hosts into a new virtualswitch query then into a new virtual port group command. Did i mention the virtual switch has a different name per host? Its vswitch0 on some, vswitch1 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2011/09/powercli.jpg"><img class="alignright size-full wp-image-692" title="powercli" src="/wp-content/uploads/2011/09/powercli.jpg" alt="" width="86" height="86" /></a>As my peers seem to like to flout convention, particularly naming conventions. I was left with a strange automation challenge this week.</p>
<p>with a new service coming online in my company, I had 12 vlan portgroups to add to over 30 ESXi machines. Simple you say, just pipe your hosts into a new virtualswitch query then into a new virtual port group command.</p>
<p>Did i mention the virtual switch has a different name per host? Its vswitch0 on some, vswitch1 on others, and even vswitch2 on one.Arse.</p>
<p>after a few hours of various queries, below is the little scripty I was left with. I did consider putting this into a function, but I didnt know where to begin when it came to a name&#8230;</p>
<p><em>add-PortGroupInSwitchWhereOtherPortGroupExists? &#8230;</em> <strong>bleh.</strong></p>
<p>Below the variables are pretty self explanatory and it works flawlessly. Remember to install the powercli commands, import the module and connect to the vi server first!</p>
<pre style="padding-left:30px;">#Variables
 $findportgroupname="GWA4"
 $NewPortGroupName="Citrix7"
 $NewPortGroupVlanId="306"

foreach ($portgroup in get-virtualportgroup | where {$_.name -eq $findportgroupname}){
 get-vmhost -id $portgroup.vmhostid |
  get-virtualswitch -name $portgroup.virtualswitchname |
   new-virtualportgroup -name $NewPortGroupName -Vlanid $NewPortGroupVlanId
 }</pre>
<p><a href="/wp-content/uploads/2011/09/results.png"><img class="aligncenter size-full wp-image-693" title="results" src="/wp-content/uploads/2011/09/results.png" alt="" width="600" height="360" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2011/09/unique-portgroup-fiddling-with-powercli/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMWare Powercli one liners &amp; simple functions:</title>
		<link>http://andrewmorgan.ie/2011/05/vmware-powercli-one-liners-simple-functions/</link>
		<comments>http://andrewmorgan.ie/2011/05/vmware-powercli-one-liners-simple-functions/#comments</comments>
		<pubDate>Mon, 16 May 2011 06:31:14 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[PowerClI]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Powercli]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Vmware]]></category>

		<guid isPermaLink="false">http://andymorgan.wordpress.com/?p=424</guid>
		<description><![CDATA[I attended the VCP 410 training course last week (install, configure &#38; manage). I found this training very interesting but the real thief of my attention was just how good the vmware vSphere Powercli modules and cmdlets were. Below are a few one-liners I wrote as the week went on out of boredom and curiosity. Hopefully I soaked in enough of the course through partial listening while reading the powercli help references to pass my exam today! Retrieve and Apply [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I attended the<a href="/wp-content/uploads/2011/05/powercli.png"><img class="alignright size-thumbnail wp-image-425" title="PowerCLI" src="/wp-content/uploads/2011/05/powercli.png?w=150" alt="" width="150" height="150" /></a> VCP 410 training course last week (install, configure &amp; manage). I found this training very interesting but the real thief of my attention was just how good the vmware vSphere Powercli modules and cmdlets were. Below are a few one-liners I wrote as the week went on out of boredom and curiosity.</p>
<p>Hopefully I soaked in enough of the course through partial listening while reading the powercli help references to pass my exam today!</p>
<p><strong>Retrieve and Apply DRS recommendations:</strong></p>
<p style="padding-left:30px;"><em>get-drsrecommendation | Apply-DrsRecommendation</em></p>
<p><strong>Find all vm&#8217;s with e1000 network cards, for upgrade to vmxnet:</strong></p>
<p style="padding-left:30px;"><em>get-vm | Get-NetworkAdapter | where {$_.type -match &#8220;e1000&#8243;} | select-object parent,networkname,name,type</em></p>
<p><strong>power off all vm&#8217;s with &#8220;test&#8221; in their names:</strong></p>
<p style="padding-left:30px;"><em>get-vm test* | stop-vm -confirm:$false</em></p>
<p><strong>Move all vm&#8217;s with &#8220;test&#8221; in their names:</strong></p>
<p style="padding-left:30px;"><strong></strong><em>get-vm | where {$_.name -like &#8220;*test&#8221;} | move-vm -destination destinationhostname<br />
</em></p>
<p><strong>Remove all vm&#8217;s with &#8220;test&#8221; in their name:</strong></p>
<p style="padding-left:30px;"><em> get-vm test* | remove-vm -confirm:$false</em></p>
<p><strong>retrieve a list of vm&#8217;s with thinly provisioned disks:</strong></p>
<p style="padding-left:30px;"><em>get-vm | select HardDisks -expandproperty HardDisks | where {$_.storageformat -match &#8220;Thin&#8221;} | select-object parent,name,capacitykb,filename</em></p>
<p><em></em><strong>A function to report on physical resources vs virtual commitment:</strong></p>
<pre style="padding-left:30px;"><em>function get-commitment {</em>
<em> $objreport=@()</em>

<em> get-vmhost | % {</em>

<em> $intvmcommitmemmb=$null</em>
<em> $intvmcommitcpu=$null</em>

<em> get-vm -location $_ | % {</em>
<em> $intvmcommitcpu += $_.numcpu</em>
<em> $intvmcommitmemmb += $_.MemoryMB</em>
<em> }#end vm</em>

<em> $objOutput = New-Object PSObject -Property @{</em>
<em> VMHost = $_.name</em>
<em> VMMaxCpu = $_.NumCpu</em>
<em> VMCommitCPU = $intvmcommitcpu</em>
<em> VMMaxMem = $_.MemoryTotalMB</em>
<em> VMCommitMem = $intvmcommitmemmb</em>
<em> }#end object</em>
<em> $objreport += $objoutput </em>
<em> }#endhost</em>

<em> return $objreport</em>
<em>}#endfunction</em>

<em>get-commitment</em></pre>
<p><strong>A function to report all machines with snapshots:</strong></p>
<pre style="padding-left:30px;"><em>function get-snapshots {</em>
<em> $i=$null </em>
<em> $result=@()</em>
<em> $objAllservers = get-vm</em>
<em> foreach ($server in $objAllservers){</em>
<em> $i++</em>
<em> $intsize = $intsize + $objallservers.length</em>
<em> Write-Progress -activity "Gathering snapshot report ($server)" -status "Percent complete: " -PercentComplete (($i / $objAllservers.length) * 100)</em>
<em> $result += get-snapshot $server}</em>

<em> return $result</em>
<em>}</em>

<em>get-snapshots | select-object name,created,sizemb,iscurrent,vm,vmid,Id,Uid</em></pre>
<p>pass the vcp exam: (work in progress)</p>
<pre style="padding-left:30px;">get-coursenotes |
select-object salespitch,minimums,maximums,configurationlimitations |
commit-tobrain | out-exampaper
<em> </em></pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2011/05/vmware-powercli-one-liners-simple-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
