<?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>PowerCLI &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/powercli/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sat, 23 Nov 2019 14:05:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>PowerShell: Schedule PowerCLI cmdlet</title>
		<link>https://blog.andreev.it/2012/07/schedule-powercli-cmdlet/</link>
					<comments>https://blog.andreev.it/2012/07/schedule-powercli-cmdlet/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Tue, 10 Jul 2012 18:30:12 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=319</guid>

					<description><![CDATA[Scheduling PowerCLI cmdlet is a bit different than scheduling standard PowerShell scripts. Here is&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Scheduling PowerCLI cmdlet is a bit different than scheduling standard PowerShell scripts. Here is an example of a script that deletes a cloned VM and sends an e-mail using the SMTP settings from vCenter.</p>
<pre class="brush: powershell; title: ; notranslate">
add-pssnapin VMware.VimAutomation.Core

Connect-VIServer vCenter_hostname -User Administrator -Password password
$vCenterSettings = Get-View -Id 'OptionManager-VpxSettings' 

$MailSender = ($vCenterSettings.Setting | Where-Object { $_.Key -eq &quot;mail.sender&quot;}).Value
$MailSmtpServer = ($vCenterSettings.Setting | Where-Object { $_.Key -eq &quot;mail.smtp.server&quot;}).Value  

Remove-VM &lt;em&gt;VM-TO-BE-DELETED&lt;/em&gt; -DeleteFromDisk -Confirm:$false

$Report = &quot;Old clone deleted, new cloning will start in 5 minutes.&quot;

Send-MailMessage -from $MailSender -to &quot;recepient@somedomain.com&quot; -subject &quot;VM clone deleted&quot; \ 
-body $Report -smtpServer $MailSmtpServer 

Disconnect-VIServer vCenter_hostname -Confirm:$false
</pre>
<p>Save this file as <strong>C:\folder\script.ps1</strong> or whatever you want to name it, and start the Windows scheduler. Make sure that <strong>Run whether user is logged on or not</strong> is selected under the <strong>General </strong>tab. Configure the settings under the trigger tab and then create a new action under <strong>Actions </strong>tab. For program/script, add <strong>C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe</strong> and for the arguments, add &#8220;<strong>&#038; &#8216;c:\folder\script.ps1&#8217;</strong>&#8220;. And, that&#8217;s it.<br />
<strong>NOTE: Pay special attention on the quotes. It starts with double quote, ampersand, space, single quote, the full path to the script, single quote, and finally double quote.</strong><br />
If the script doesn&#8217;t work, it&#8217;s probably because you have a newer version of PowerCLI. Use <strong>Import-Module -Name VMware.PowerCLI</strong> instead of <strong>add-pssnapin VMware.VimAutomation.Core</strong>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2012/07/schedule-powercli-cmdlet/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
