<?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>Edwin M SarmientoWindows PowerShell &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/category/windows-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>Installing, Configuring and Managing Windows Server Failover Cluster using PowerShell Series</title>
		<link>https://www.edwinmsarmiento.com/installing-configuring-and-managing-windows-server-failover-cluster-using-powershell-series/</link>
		<comments>https://www.edwinmsarmiento.com/installing-configuring-and-managing-windows-server-failover-cluster-using-powershell-series/#respond</comments>
		<pubDate>Tue, 23 Sep 2014 14:18:47 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[clustering]]></category>
		<category><![CDATA[High Availability]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows Cluster]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[Windows Server Failover Clustering]]></category>
		<category><![CDATA[WSFC]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/?p=909</guid>

				<description><![CDATA[Last year, I started writing an article that was supposed to be a series for Installing, Configuring and Managing Windows Server Failover Cluster using Windows PowerShell. The first of the series came out on July 2013 (which ended up being the last article I wrote for the year 2013 on MSSQLTips.com.) Since then, I&#8217;ve been involved [&#8230;]]]></description>
					<content:encoded><![CDATA[<p>Last year, I started writing an article that was supposed to be a series for Installing, Configuring and Managing Windows Server Failover Cluster using Windows PowerShell. The <a href="http://www.mssqltips.com/sqlservertip/3001/installing-configuring-and-managing-windows-server-failover-clusters-using-powershell-part-1/" target="_blank">first</a> of the series came out on July 2013 (which ended up being the last article I wrote for the year 2013 on MSSQLTips.com.) Since then, I&#8217;ve been involved with more projects on SharePoint and business intelligence (BI) integration that I barely had a chance to work with the SQL Server database engine on a regular basis. But since part 1 of the series is already out there, I figured it&#8217;s worth the time and effort to finish it up. So, here it is &#8211; the complete series on Installing, Configuring and Managing Windows Server Failover Cluster using Windows PowerShell.</p>
<ul>
<li><a href="http://www.mssqltips.com/sqlservertip/3001/installing-configuring-and-managing-windows-server-failover-clusters-using-powershell-part-1/" target="_blank">Part 1</a> &#8211; from installing the feature to creating the Windows Server Failover Cluster</li>
<li><a href="http://www.mssqltips.com/sqlservertip/3325/installing,-configuring-and-managing-windows-server-failover-cluster-using-powershell-part-2/" target="_blank">Part 2</a> &#8211; retrieving and changing cluster object properties and adding clustered disks</li>
<li><a href="http://www.mssqltips.com/sqlservertip/3326/install-configure-and-manage-windows-server-failover-cluster-with-powershell--part-3/" target="_blank">Part 3</a> &#8211; managing permissions, changing parameter values, moving clustered resources and dependencies</li>
<li><a href="http://www.mssqltips.com/sqlservertip/3343/installing-configuring-and-managing-windows-server-failover-cluster-using-powershell-part-4/" target="_blank">Part 4</a> &#8211; common cluster troubleshooting tasks</li>
</ul>
<p>Enjoy!</p>
<h1></h1>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/installing-configuring-and-managing-windows-server-failover-cluster-using-powershell-series/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">909</post-id>	</item>
		<item>
		<title>People Talking Tech with MrDenny</title>
		<link>https://www.edwinmsarmiento.com/people-talking-tech-with-mrdenny/</link>
		<comments>https://www.edwinmsarmiento.com/people-talking-tech-with-mrdenny/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 22:26:57 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/?p=722</guid>

				<description><![CDATA[I&#8217;ve totally forgotten about this because we did it late last year. SQL Server MVP (VMWare vExpert Awardee, EMC Elect Awardee, etc.) Denny Cherry (blog &#124; Twitter) was kind enough to have me on his podcast. We talked about Windows PowerShell and how it can help SQL Server DBAs maximize their productivity performing tasks that, [&#8230;]]]></description>
					<content:encoded><![CDATA[<p>I&#8217;ve totally forgotten about this because we did it late last year. SQL Server MVP (VMWare vExpert Awardee, EMC Elect Awardee, etc.) Denny Cherry (<a href="http://mrdenny.com/blogs" target="_blank">blog</a> | <a href="http://twitter.com/mrdenny" target="_blank">Twitter</a>) was kind enough to have me on his podcast. We talked about Windows PowerShell and how it can help SQL Server DBAs maximize their productivity performing tasks that, in some cases, are challenging to do with Transact-SQL.</p>
<p>MrDenny, thanks for the wonderful opportunity to be a part of <a href="http://peopletalkingtech.com/" target="_blank">People Talking Tech</a>.</p>
<p><strong><a class="powerpress_link_pinw" title="Play in new window" href="http://media.blubrry.com/peopletalkingtech/p/peopletalkingtech.com/eps/Episode_017_Edwin_Sarmiento-c.mp3" target="_blank" rel="nofollow">Play in new window</a> | <a class="powerpress_link_d" title="Download" href="http://media.blubrry.com/peopletalkingtech/p/peopletalkingtech.com/eps/Episode_017_Edwin_Sarmiento-c.mp3" rel="nofollow">Download</a></strong></p>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/people-talking-tech-with-mrdenny/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<enclosure url="http://media.blubrry.com/peopletalkingtech/p/peopletalkingtech.com/eps/Episode_017_Edwin_Sarmiento-c.mp3" length="24822594" type="audio/mpeg" />
		<post-id xmlns="com-wordpress:feed-additions:1">722</post-id>	</item>
		<item>
		<title>Export and Import Hyper-V 3.0 Virtual Machines Using PowerShell</title>
		<link>https://www.edwinmsarmiento.com/export-and-import-hyper-v-3-0-virtual-machines-using-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/export-and-import-hyper-v-3-0-virtual-machines-using-powershell/#respond</comments>
		<pubDate>Fri, 23 Nov 2012 23:38:49 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[Windows Server 2012]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/?p=697</guid>

				<description><![CDATA[When you run a server operating system in your laptop, there&#8217;s a ton of stuff that you need to consider. Today, I spent almost the entire day trying to make sure that all of the drivers work on my DELL Latitude E6520. And since I run the Hyper-V role on my Windows Server 2012 machine, the [&#8230;]]]></description>
					<content:encoded><![CDATA[<p>When you run a server operating system in your laptop, there&#8217;s a ton of stuff that you need to consider. Today, I spent almost the entire day trying to make sure that all of the drivers work on my <a href="http://amzn.to/V2z3fa" target="_blank">DELL Latitude E6520</a>. And since I run the Hyper-V role on my Windows Server 2012 machine, the first thing I did was to import all of my virtual machines from the old laptop to the new laptop. I currently have at least 14 virtual machines in my laptop. Since I do a lot of high availability and disaster recovery presentations, having that many virtual machines is just the norm for me. I took my external hard drive and started exporting all of my virtual machines.</p>
<pre class="brush: powershell; title: ; notranslate">
Get-VM | Export-VM -Path &amp;quot;F:VirtualMachines&amp;quot;
</pre>
<p>That command exports all of the Hyper-V virtual machines from my old laptop and copy them to the external hard drive. After plugging in the external hard drive to the new laptop, I copied the entire folder to the D: drive. Once the copy process was completed, I imported all of the virtual machines into Hyper-V.</p>
<pre class="brush: powershell; title: ; notranslate">
PS D:VirtualMachines&amp;gt; Get-ChildItem -recurse *.xml | Import-VM
</pre>
<p>Pretty slick especially when you&#8217;re dealing with several Hyper-V 3.0 virtual machines that you need to copy from one machine to another. And, as always, the simplicity of a one-liner command is what I use to convince IT administrators to start playing around with Windows PowerShell. Exporting and importing my Hyper-V virtual machines only took less than 20 minutes.</p>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/export-and-import-hyper-v-3-0-virtual-machines-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">697</post-id>	</item>
		<item>
		<title></title>
		<link>https://www.edwinmsarmiento.com/602/</link>
		<comments>https://www.edwinmsarmiento.com/602/#respond</comments>
		<pubDate>Mon, 12 Mar 2012 14:37:19 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[24 Hours of PASS]]></category>
		<category><![CDATA[SQL PASS]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server learning]]></category>
		<category><![CDATA[SQLPASS]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/?p=602</guid>

				<description><![CDATA[Indulge in free online SQL Server training on March 21, 2012 beginning at 00:00 GMT (that’s a March 20 evening start for the Americas). As this is an online event, act fast and register as soon as you can because seats are limited. Check out the 24 Hours of PASS website for more details. I will be delivering [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><a href="https://bassplayerdoc.files.wordpress.com/2012/03/24hop_speakerbanner_spring2012.jpg"><img decoding="async" class="size-full wp-image-603 aligncenter" title="24HOP_Speaker+Banner_Spring+2012" src="https://bassplayerdoc.files.wordpress.com/2012/03/24hop_speakerbanner_spring2012.jpg" alt="" width="246" height="96" srcset="https://www.edwinmsarmiento.com/wp-content/uploads/2012/03/24hop_speakerbanner_spring2012.jpg 246w, https://www.edwinmsarmiento.com/wp-content/uploads/2012/03/24hop_speakerbanner_spring2012-82x32.jpg 82w" sizes="(max-width: 246px) 100vw, 246px" /></a>Indulge in free online SQL Server training on March 21, 2012 beginning at <a href="http://www.sqlpass.org/24hours/spring2012/TimeZones.aspx">00:00 GMT</a> (that’s a March 20 evening start for the Americas). As this is an online event, act fast and register as soon as you can because seats are limited. Check out the <a href="http://www.sqlpass.org/24hours/spring2012/default.aspx" target="_blank">24 Hours of PASS website</a> for more details. I will be delivering a session on <a href="http://www.sqlpass.org/24hours/spring2012/SessionsbySchedule/SessionDetails.aspx?sid=2529" target="_blank">SQL Server 2012 on Windows Server Core</a> on the 12 NN (Eastern). Watch out for more information on Twitter using the #24HOP hashtag.</p>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/602/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">602</post-id>	</item>
		<item>
		<title>Clone Your SQL Server Databases Using SMO and PowerShell</title>
		<link>https://www.edwinmsarmiento.com/clone-your-sql-server-databases-using-smo-and-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/clone-your-sql-server-databases-using-smo-and-powershell/#respond</comments>
		<pubDate>Sun, 14 Aug 2011 01:57:36 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[SMO]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/?p=480</guid>

				<description><![CDATA[Back in 2009, I wrote an article about how to generate SQL scripts using Windows PowerShell and Server Management Objects (SMO) using the Script() method. One thing that you need to consider when using the Script() method is making sure that you have taken into account all of the database objects as well as their [&#8230;]]]></description>
					<content:encoded><![CDATA[<p>Back in 2009, I wrote an article about how to <a href="http://www.mssqltips.com/sqlservertip/1842/generating-sql-scripts-using-windows-powershell/" target="_blank">generate SQL scripts using Windows PowerShell and Server Management Objects (SMO)</a> using the Script() method. One thing that you need to consider when using the Script() method is making sure that you have taken into account all of the database objects as well as their related objects. Take, for example, the Table object (or <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.table.aspx" target="_blank">Table class</a> according to SMO). A Table object consists of a collection of <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.column.aspx" target="_blank">columns</a>. Each column consists of several properties that can be considered database objects such as primary and foreign keys, constraints, etc. This means that for every column, you need to iterate thru all the possible constraints. Same thing with triggers and indexes. And we&#8217;re just looking at one database object here with multiple dependencies &#8211; the Table.</p>
<p>This is something that I needed to deal with when one of my customers wanted me to fix a process that included running a backup and restoring it on another server as well as truncating the tables.  They simply needed to clone their database structure for testing purposes. I highlighted the fact that the backup/restore/table truncate process is utilizing a lot of unnecessary resources &#8211; network, disk and CPU &#8211; when all they needed was the database structure. That&#8217;s where I recommended using database creation scripts. It&#8217;s lightweight and does not utilize unnecessary resources. While I&#8217;m a big fan of process automation, I emphasize the need for proper definition of the process as well as making the process as simple as I possibly can. This PowerShell script is just one of the steps included in that process.</p>
<pre class="brush: powershell; title: ; notranslate">
$sourcePath=&amp;quot;C:temp&amp;quot; #Variable to contain location of SQL scripts

$s=new-object ('Microsoft.SqlServer.Management.Smo.Server') &amp;quot;LOCALHOST&amp;quot;

#Assign object to the database selected
$dbs=$s.Databases

#Script database creation - adding GO statement
$dbs&#x5B;&amp;quot;$database&amp;quot;].Script() +&amp;quot;`r`nGO`r`nUSE &#x5B;$database]`r`nGO`r`n&amp;quot; | Out-File $sourcePath$database.sql -append

#Generate script for all tables, excluding system tables
foreach ($tablesin$dbs&#x5B;&amp;quot;$database&amp;quot;].Tables | where {$_.IsSystemObject -eq$false})
{
$tables.Script() +&amp;quot;`r`nGO`r`n&amp;quot; | Out-File$sourcePath$database.sql -append

#Generate script for all indexes in the specified table
foreach($indexin$tables.Indexes)
{
$index.Script() +&amp;quot;`r`nGO`r`n&amp;quot; | Out-File$sourcePath$database.sql -append
}

#Generate script for all triggers in the specified table
foreach($triggerin$tables.Triggers)
{
$trigger.Script() +&amp;quot;`r`nGO`r`n&amp;quot; | Out-File$sourcePath$database.sql -append
}

#Generate Default Constraints on columns that have them
#Iterate thru all the columns in the table
foreach($columnin$tables.Columns)
{
#Iterate thru all the default constraints in the columns
foreach($defaultin$column.DefaultConstraint)
{
#If there are default constraints, script out the ADD CONSTRAINT command
if ($default-ne$null)
{
$default.Script() +&amp;quot;`r`nGO`r`n&amp;quot; | Out-File$sourcePath$database.sql -append
}
}
}

}
</pre>
<p>You can literally dig deeper on the different properties of the Table class to generate the corresponding script for the objects that you wish to create. Happy scripting!</p>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/clone-your-sql-server-databases-using-smo-and-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">480</post-id>	</item>
		<item>
		<title>Retrieve Default SQL Server Backup Folder using PowerShell</title>
		<link>https://www.edwinmsarmiento.com/retrieve-default-sql-server-backup-folder-using-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/retrieve-default-sql-server-backup-folder-using-powershell/#respond</comments>
		<pubDate>Wed, 28 Apr 2010 17:41:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Server Management Objects]]></category>
		<category><![CDATA[SMO]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2010/04/28/retrieve-default-sql-server-backup-folder-using-powershell</guid>

				<description><![CDATA[As I&#8217;ve been translating a lot of my TSQL script to Windows PowerShell with SMO, here&#8217;s another articleI wrote on how to check for the default SQL Server backup folder]]></description>
					<content:encoded><![CDATA[<p>As I&#8217;ve been translating a lot of my TSQL script to Windows PowerShell with SMO, here&#8217;s another <a href="http://www.mssqltips.com/tip.asp?tip=1985">article</a>I wrote on how to check for the default SQL Server backup folder</p>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/retrieve-default-sql-server-backup-folder-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">212</post-id>	</item>
		<item>
		<title>Connecting to SQL Server via Windows PowerShell with SQL Server authentication</title>
		<link>https://www.edwinmsarmiento.com/connecting-to-sql-server-via-windows-powershell-with-sql-server-authentication/</link>
		<comments>https://www.edwinmsarmiento.com/connecting-to-sql-server-via-windows-powershell-with-sql-server-authentication/#respond</comments>
		<pubDate>Mon, 22 Feb 2010 18:50:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2010/02/22/connecting-to-sql-server-via-windows-powershell-with-sql-server-authentication</guid>

				<description><![CDATA[Most of the articles I&#8217;ve written about SQL Server with Windows PowerShell have been using Windows Authentication. And while it is highly recommended to use Windows authentication to connect to SQL Server, the reality is that the IT infrastructures we have don&#8217;t run on Microsoft Windows. Here&#8217;s an article I wrote on how to use [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">Most of the articles I&#8217;ve written about SQL Server with Windows PowerShell have been using Windows Authentication. And while it is highly recommended to use Windows authentication to connect to SQL Server, the reality is that the IT infrastructures we have don&#8217;t run on Microsoft Windows.</span></p>
<p><span style="font-family:arial;">Here&#8217;s an </span><a href="http://www.mssqltips.com/tip.asp?tip=1947"><span style="font-family:arial;">article</span></a><span style="font-family:arial;"> I wrote on how to use Windows PowerShell to connect to SQL Server via mixed mode authentication</span></p>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/connecting-to-sql-server-via-windows-powershell-with-sql-server-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">209</post-id>	</item>
		<item>
		<title>Query Hyper-V Virtual machines using Windows PowerShell</title>
		<link>https://www.edwinmsarmiento.com/query-hyper-v-virtual-machines-using-windows-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/query-hyper-v-virtual-machines-using-windows-powershell/#respond</comments>
		<pubDate>Tue, 16 Feb 2010 23:19:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2010/02/16/query-hyper-v-virtual-machines-using-windows-powershell</guid>

				<description><![CDATA[Being a lazy administrator as I am, I try to minimize the amount of mouse-clicks I need to make to retrieve information about something on a Windows platform. As I have been using Microsoft Hyper-V on a bunch of my test machines, I always check if a VM is up and running before I power [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">Being a lazy administrator as I am, I try to minimize the amount of mouse-clicks I need to make to retrieve information about something on a Windows platform. As I have been using Microsoft Hyper-V on a bunch of my test machines, I always check if a VM is up and running before I power down my host machine (imagine the amount of electricity consumed just by keeping your machine up and running even without using it). This is specifically the case when dealing with my Windows XP VMs. I noticed that the profiles get corrupted if I shutdown the host machine without properly shutting down the VM. So, I always made sure that the VMs are not running before powering down the host machine.</span></p>
<p><span style="font-family:arial;">I wrote a PowerShell command to query the current state of the VMs running on Hyper-V</span></p>
<pre class="brush: powershell; title: ; notranslate">
Get-WMIObject -class &amp;quot;MSVM_ComputerSystem&amp;quot;-namespace &amp;quot;rootvirtualization&amp;quot;-computername &amp;quot;.&amp;quot;
</pre>
<p><span style="font-size:85%;"><span style="font-family:arial;">This will actually display a bunch of information about the VMs running on Hyper-V but what we&#8217;re really concerned about is the name of the VM and it&#8217;s currently running state. These two properties are associated with the ElementName and EnabledState attributes of the </span><a href="http://msdn.microsoft.com/en-us/library/cc136822(VS.85).aspx"><span style="font-family:arial;">MSVM_ComputerSystem</span></a><span style="font-family:arial;"> class. All we need to do with the command above is to pipe the results to a <a href="http://technet.microsoft.com/en-us/library/dd315291.aspx">Select-Object</a> cmdlet, specifying only these two properties, as follows</span></span></p>
<pre class="brush: powershell; title: ; notranslate">
Get-WMIObject -class &amp;quot;MSVM_ComputerSystem&amp;quot;-namespace &amp;quot;rootvirtualization&amp;quot;-computername &amp;quot;.&amp;quot; | Select-Object ElementName, EnabledState
</pre>
<p><span style="font-family:arial;"> While the <strong>EnabledState</strong> property will give you a bunch of numbers, I&#8217;m only concerned with those values equal to 2, which means that the VM is running. But, then, you might not remember what the value 2 means. So might as well write an entire script that checks for the value of the <strong>EnabledState</strong> property. I&#8217;ve used the GWMI alias to call the <strong>Get-WMIObject</strong> cmdlet</span></p>
<pre class="brush: powershell; title: ; notranslate">
$VMs = gwmi -class &amp;quot;MSVM_ComputerSystem&amp;quot;-namespace &amp;quot;rootvirtualization&amp;quot;-computername &amp;quot;.&amp;quot;
foreach ($VM IN $VMs)
{
switch ($VM.EnabledState)
{
2{$state=&amp;quot;Running&amp;quot; }
3{$state=&amp;quot;Stopped&amp;quot; }
32768{$state=&amp;quot;Paused&amp;quot; }
32769{$state=&amp;quot;Suspended&amp;quot; }
32770 {$state=&amp;quot;Starting&amp;quot; }
32771{$state=&amp;quot;Taking Snapshot&amp;quot; }
32773{$state=&amp;quot;Saving&amp;quot; }
32774{$state=&amp;quot;Stopping&amp;quot; }
}
write-host $VM.ElementName `,` $state
}

</pre>
<p><span style="font-family:arial;">On a side note, make sure you are running as Administrator when working with this script as you will only see the VMs that your currently logged in profile has permission to access. Running as Administrator will show you all of the VMs configured on your Hyper-V server</span></p>
<div class="blogger-post-footer"></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/query-hyper-v-virtual-machines-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">208</post-id>	</item>
		<item>
		<title>Creating Active Directory Users with Windows PowerShell</title>
		<link>https://www.edwinmsarmiento.com/creating-active-directory-users-with-windows-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/creating-active-directory-users-with-windows-powershell/#respond</comments>
		<pubDate>Fri, 03 Jul 2009 23:52:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[Active Directory users]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2009/07/03/creating-active-directory-users-with-windows-powershell</guid>

				<description><![CDATA[While it may seem easy to create Active Directory users using the management console, I still prefer doing it using scripts so as to make sure that they are done in a uniform, standard fashion (not to mention as fast as one can possibly do especially if you will be doing it for many users). [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">While it may seem easy to create Active Directory users using the management console, I still prefer doing it using scripts so as to make sure that they are done in a uniform, standard fashion (not to mention as fast as one can possibly do especially if you will be doing it for many users). I&#8217;ve referenced the scripts provided at the CodePlex site for <a href="http://www.codeplex.com/PsObject/Wiki/View.aspx?title=ADSI%20and%20AD">ADSI and Active Directory</a> for Windows PowerShell (full credit goes to them) to create users in Active Directory for Windows Server 2008. This also works for Windows Server 2003. While I may be a big fan of automation, it is important to highlight that processes are what makes automation really work. The reason I am saying this is that the CSV file can come from different sources, say, an intranet site where you ask employees to log in and key in their details. Having a process in place to make sure that users who would be entering their details in a standard way would eliminate the need to cleanse the data (I&#8217;m still thinking as a DBA here) in the long run. Plus, having a standard in place as an organization is starting out will make it flexible enough to scale as growth happens.</span></p>
<pre class="brush: powershell; title: ; notranslate">
# define constants
$domainstr = &amp;quot;,dc=domainName,dc=local&amp;quot;
$domainnb = &amp;quot;domainName&amp;quot; # domain netbios name
$domain = &amp;quot;domainName.local&amp;quot;

$ADs_UF_NORMAL_ACCOUNT = 512 # Disables account and sets password required.

# Remember to enable the account before logging in

# Prompt user to enter the default passsword for the users
$defaultPassword = Read-Host &amp;quot;Please enter default Password:&amp;quot; -asSecureString

# Read the list of users from the CSV file
# Include other user properties in the CSV file as necessary

Import-csv users.txt | foreach
{
# Create user name based on FirstName and LastName column in the CSV file
$strUser = $_.firstName + &amp;quot; &amp;quot; + $_.lastName

#Form the LDAP string based on the OU column from the CSV file
$strLDAP = &amp;quot;LDAP://OU=&amp;quot; + $_.OU + &amp;quot;,OU=domainName Domain Users&amp;quot; + $domainstr

$target = &#x5B;ADSI] $strLDAP
$newUser = $target.create(&amp;quot;User&amp;quot;, &amp;quot;cn=&amp;quot; + $strUser)
$newUser.SetInfo()

#Define a naming convention for the login based on your corporate policy
#This one uses the first letter of the firstname and the lastname
$userID = $_.firstName&#x5B;0]+$_.lastName

#Define the other user attributes based on the columns defined in the CSV file
$newUser.sAMAccountName = $userID.ToString()
$newUser.givenName = $_.firstName
$newUser.sn = $_.lastName
$newUser.displayName = $_.firstName + &amp;quot; &amp;quot; + $_.lastName
$newUser.userPrincipalName = $_.firstName&#x5B;0]+$_.lastName + &amp;quot;@&amp;quot; + $domain
$newUser.mail = $_.Email
$newUser.physicalDeliveryOfficeName = $_.Location
$newUser.title = $_.Designation
$newUser.description = $_.Designation
$newUser.SetInfo()

$newUser.SetPassword($defaultPassword.ToString())

#Normal user that requires password &amp;amp; is disabled
$newUser.userAccountControl = $ADs_UF_NORMAL_ACCOUNT

Write-Host &amp;quot;Created Account for: &amp;quot; $newUser.Displayname

}
</pre>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/creating-active-directory-users-with-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">194</post-id>	</item>
		<item>
		<title>Check the last backup date in SQL Server using Windows PowerShell</title>
		<link>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/</link>
		<comments>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/#respond</comments>
		<pubDate>Tue, 16 Jun 2009 23:32:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[last backup date]]></category>
		<category><![CDATA[modify SQL Server logins]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2009/06/16/check-the-last-backup-date-in-sql-server-using-windows-powershell</guid>

				<description><![CDATA[This article highlights how to use Windows PowerShell to retrieve database properties using SMO. Notice how easy it is to check the database properties using pretty common syntax One of the challenges I have when I was starting out as a SQL Server DBA was to check for the last backup date for a database. [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">This <a href="http://mssqltips.com/tip.asp?tip=1759">article </a>highlights how to use Windows PowerShell to retrieve database properties using SMO. Notice how easy it is to check the database properties using pretty common syntax</span></p>
<p>One of the challenges I have when I was starting out as a SQL Server DBA was to check for the last backup date for a database. One way to do this is to find out which tables in the MSDB database contain the records of the backup history. What&#8217;s really challenging here is the fact that you would have to look at the tables and their corresponding relationships which, apparently, MSDB doesn&#8217;t have. You simply have to rely on what SQL Server Books Online has to say. Plus, the MSDB database will only contain records for databases with backups. What about those without?</p>
<p>For SQL Server 2005, the script below displays the last backup date of all the databases on your SQL Server instance. This script is from the <a href="http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=LastBackUpDate">MSDN Code Gallery</a></p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT<br />
</span><span style="color:black;">T1.Name </span><span style="color:blue;">AS </span><span style="color:black;">DatabaseName</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">COALESCE</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">12</span><span style="color:gray;">), </span><span style="color:blue;">MAX</span><span style="color:gray;">(</span><span style="color:black;">T2.backup_finish_date</span><span style="color:gray;">), </span><span style="color:black;">101</span><span style="color:gray;">),</span><span style="color:red;">'Not Yet Taken'</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">LastBackUpTaken</span><span style="color:black;"><br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.sysdatabases T1 </span><span style="color:magenta;">LEFT </span><span style="color:gray;">OUTER </span><span style="color:blue;">JOIN </span><span style="color:black;">msdb.dbo.backupset T2<br />
</span><span style="color:blue;">ON </span><span style="color:black;">T2.database_name </span><span style="color:blue;">= </span><span style="color:black;">T1.name<br />
</span><span style="color:blue;">GROUP BY </span><span style="color:black;">T1.Name<br />
</span><span style="color:blue;">ORDER BY </span><span style="color:black;">T1.Name<br />
</span></code><br />
<span style="font-family:arial;">You can simply replace the <span style="font-size:85%;"><span style="font-weight:bold;">sys.sysdatabases</span></span> table with <span style="font-size:85%;"><span style="font-weight:bold;">master.dbo.sysdatabases</span></span> for SQL Server 2000</span></p>
<p>Below is the equivalent script using Windows PowerShell.</p>
<pre class="brush: powershell; title: ; notranslate">
$instance=&amp;quot;Your_SQL_Server_Instance_Name&amp;quot;
&#x5B;System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')| out-null

# Create an SMO connection to the instance
$s = new-object ('Microsoft.SqlServer.Management.Smo.Server') $instance

$dbs = $s.Databases
$dbs | select Name,LastBackupDate, LastLogBackupDate | format-table -autosize
</pre>
<p>The only thing to note here are the last two lines &#8211; the one that creates an instance of the database object and the one that displays and formats a few of the database object properties. The first few lines will be the same for just about any PowerShell script that will access SQL Server using SMO</p>
<div class="blogger-post-footer"><img decoding="async" src="" alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/check-the-last-backup-date-in-sql-server-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">192</post-id>	</item>
	</channel>
</rss>