<?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>Workflow Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/workflow/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/workflow/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Tue, 17 Mar 2015 21:49:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.10</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>Workflow Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/workflow/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>PowerCLI and PowerShell Workflows</title>
		<link>https://www.lucd.info/2015/03/17/powercli-and-powershell-workflows/</link>
					<comments>https://www.lucd.info/2015/03/17/powercli-and-powershell-workflows/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Tue, 17 Mar 2015 19:54:14 +0000</pubDate>
				<category><![CDATA[Module]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Workflow]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=4878</guid>

					<description><![CDATA[In PowerShell v3 the Workflow feature was introduced. But until now there haven&#8217;t [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In <strong>PowerShell v3</strong> the <a href="https://technet.microsoft.com/en-us/library/jj134242.aspx" target="_blank">Workflow feature</a> was introduced. But until now there haven&#8217;t been too many examples available on how to use <strong>PowerCLI</strong> in PowerShell Workflows. Today I was triggered by a <a href="https://communities.vmware.com/thread/505283" target="_blank">thread</a> from Mark in the <a href="https://communities.vmware.com/community/vmtn/automationtools/powercli" target="_blank">PowerCLI VMTN community,</a> to revise some of my Workflow code snippets I had laying around.</p>
<p style="padding-left: 120px;"><a href="https://www.lucd.info/2015/03/17/powercli-and-powershell-workflows/workflow-powercli/" rel="attachment wp-att-4880"><img fetchpriority="high" decoding="async" class="alignnone wp-image-4880 size-medium" src="https://lucd.info/wp-content/uploads/2015/03/Workflow-PowerCLI-300x196.png" alt="Workflow-PowerCLI" width="300" height="196" srcset="https://www.lucd.info/wp-content/uploads/2015/03/Workflow-PowerCLI-300x196.png 300w, https://www.lucd.info/wp-content/uploads/2015/03/Workflow-PowerCLI.png 477w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>And if you didn&#8217;t have enough arguments yet to upgrade to <a href="https://my.vmware.com/group/vmware/get-download?downloadGroup=PCLI600R1">PowerCLI v6</a>, which brings <span style="background-color: #ffff00;"><strong>MODULES</strong></span>, the Workflow feature will give you another one !</p>
<p><span id="more-4878"></span></p>
<p>To get a quick introduction on what PowerShell Workflows are about, read the excellent article by <a href="https://twitter.com/alexandair" target="_blank">Aleksandar</a>, called <a href="https://www.powershellmagazine.com/2012/11/14/powershell-workflows/" target="_blank">PowerShell Workflows</a>,  in the <a href="https://www.powershellmagazine.com/" target="_blank">PowerShellMagazine</a>. <a href="https://twitter.com/alexandair" target="_blank">Aleksandar</a> also did a session on the subject at the <a href="https://www.nicconf.com/" target="_blank">Nordic Infrastructure Conference</a> in 2015, you can find a recording of his session <a href="https://www.nicconf.com/powershell-workflows-prepare-yourself-for-sma-and-azure-automation" target="_blank">here</a>.  For some more in depth information consult the <strong>TechNet</strong> article called <a href="https://technet.microsoft.com/en-us/library/jj134242.aspx" target="_blank">Getting Started with Windows PowerShell Workflow</a>.</p>
<p>When trying to use PowerCLI in PowerShell Workflows, there are a couple of things you should be aware off.</p>
<ul>
<li>Inside a Worklfow script not all cmdlets are supported. The <strong>Add-PSSnapin</strong> cmdlet is one of those. When you are using <strong>PowerCLI v6</strong> this no problem, since you will be using the <strong>module autoloading</strong> feature.</li>
<li>Inside a Workflow script not all variables are available. This includes the <strong>$global:DefaultVIServer</strong> variable, so you will have to pass this information to the Workflow script via one or more parameters.</li>
<li>Your current vSphere Server connection is not available inside the Workflow. You can use the <strong>SessionId</strong> to connect to your current session inside the Workflow script</li>
<li>To run commands, that are normally not supported inside a Workflow script, you can use the <strong>InlineScript</strong> feature.</li>
<li>Accessing variables inside an InlineScript block requires that you use the <strong>$Using</strong> scope</li>
</ul>
<p>The following simple example shows how you can &#8220;get&#8221; a number of Virtual Machines in <strong>parallel</strong> workflows.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">workflow test {
   param(
      [string]$vcenter,
      [string[]]$names,
      [string]$session
   )

   foreach -parallel($name in $names){
      $vm = InlineScript{
         Connect-VIServer -Server $Using:vcenter -Session $Using:session | Out-Null
         Get-VM -Name $Using:name
      }
      $vm.Name
   }
}

$vmNames = 'vm1','vm2','vm3'
test -names $vmNames -vcenter $global:DefaultVIServer.Name -session $global:DefaultVIServer.SessionSecret</pre><p></p>
<p>When you are not yet migrated to <strong>PowerCLI v6</strong>, you will have to include the <strong>Add-PSSnapin</strong> cmdlet, The following shows the same parallel workflow but then for a pre-PowerCLI v6 environment.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">workflow test {
   param(
      []string]$vcenter,
      [string[]]$names,
      [string]$session
   )

   foreach -parallel($name in $names){
      $vm = InlineScript{
         Add-PSSnapin VMware.VimAutomation.Core
         Connect-VIServer -Server $Using:vcenter -Session $Using:session | Out-Null
         Get-VM -Name $Using:name
      }
      $vm.Name
   }
}

$vmNames = 'vm1','vm2','vm3'
test -names $vmNames -vcenter 'MyvCenter' -session $global:DefaultVIServer.SessionSecret</pre><p></p>
<p>These sample scripts are quite simple in what they actually do, but you can use any of the PowerCLI cmdlets in the InlineScript. You can for example create ten new Virtual Machines in parallel with this technique.</p>
<p>If you have some exciting use cases with PowerCLI and PowerShell Workflows feel free to add them to the comments.</p>
<p>Enjoy !</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2015/03/17/powercli-and-powershell-workflows/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
	</channel>
</rss>
