<?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>Max Trinidad - The PowerShell Front</title>
	<atom:link href="http://www.maxtblog.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maxtblog.com</link>
	<description>A little of everything about PowerShell!!!</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:52:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PowerShell quick list of SQL Users with SysAdmin Role</title>
		<link>http://www.maxtblog.com/2012/02/powershell-quick-list-of-sql-users-with-sysadmin-roles/</link>
		<comments>http://www.maxtblog.com/2012/02/powershell-quick-list-of-sql-users-with-sysadmin-roles/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 17:18:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Office]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=1004</guid>
		<description><![CDATA[Here&#8217;s a quick way to start getting a list of SQL Server users having &#8220;SysAdmin&#8221; Role.  Basically, I&#8217;m using SQLPS module (now available with SQL Server 2012) which loads all the SMO needed to help you script against your SQL &#8230; <a href="http://www.maxtblog.com/2012/02/powershell-quick-list-of-sql-users-with-sysadmin-roles/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick way to start getting a list of SQL Server users having &#8220;SysAdmin&#8221; Role.  Basically, I&#8217;m using SQLPS module (now available with SQL Server 2012) which loads all the SMO needed to help you script against your SQL engine.</p>
<p>This script does the following:</p>
<ol>
<li>Import the SQLPS Module.</li>
<li>Connect to a SQL Server Instance.</li>
<li>Get the SQL Logins information.</li>
<li>Search for SQL users with &#8220;SysAdmin&#8221; Role, and builds a customized information in a PSObject.</li>
<li>Export the information to a CSV file.</li>
<li>Open the CSV file, which by default could open an Excel application(if installed on machine).</li>
</ol>
<p>Here&#8217;s the code:</p>
<pre class="brush: powershell; title: ; notranslate">
Import-Module SQLPS -disablenamechecking

$SQLSvr = &quot;SQLServername\Instancename&quot;;
$MySQL = new-object Microsoft.SqlServer.Management.Smo.Server $SQLSvr;
$SQLLogins = $MySQL.Logins;

$SysAdmins = $null;
$SysAdmins = foreach($SQLUser in $SQLLogins)
{
	foreach($role in $SQLUser.ListMembers())
	{
		if($role -match 'sysadmin')
		{
		    Write-Host &quot;SysAdmins found: $($SQLUser.Name)&quot; -ForegroundColor Yellow;
		    $SQLUser | Select-Object `
		     @{label = &quot;SQLServer&quot;; Expression = {$SQLSvr}}, `
		     @{label = &quot;CurrentDate&quot;; Expression = {(Get-Date).ToString(&quot;yyyy-MM-dd&quot;)}}, `
		     Name, LoginType, CreateDate, DateLastModified;
		};
	};
};

$SysAdmins | Export-Csv -Path 'C:\temp\SQLSysAdminList.csv' -Force -NoTypeInformation;
ii 'C:\temp\SQLSysAdminList.csv';
</pre>
<div id="attachment_1006" class="wp-caption aligncenter" style="width: 1042px"><a href="http://www.maxtblog.com/wp-content/uploads/2012/02/ListSysAdminRoles.jpg"><img class="size-full wp-image-1006" title="ListSysAdminRoles" src="http://www.maxtblog.com/wp-content/uploads/2012/02/ListSysAdminRoles.jpg" alt="" width="1032" height="543" /></a><p class="wp-caption-text">Sample CSV output</p></div>
<p>Eventually, you could make changes to this scritp to be capable to access a list of SQL Servers and build your custom report.</p>
<p>Bonus:</p>
<p>To add the functionallity to connect to multiple servers, we can add a list of Servers and then using the &#8220;Foreach&#8221; statement to loop through the list, and with little changes to the previous code.</p>
<p>Here&#8217;s how it will look with just adding a few more line of code:</p>
<pre class="brush: powershell; title: ; notranslate">
## - Loads SQL Powerhell SMO and commands:
Import-Module SQLPS -disablenamechecking

## - BUild list of Servers manually (this builds an array list):
$SQLServers = &quot;Server01&quot;,&quot;Server01\InstanceNameA&quot;,&quot;Server03&quot;;
$SysAdmins = $null;
foreach($SQLSvr in $SQLServers)
{

	## - Add Code block:
	$MySQL = new-object Microsoft.SqlServer.Management.Smo.Server $SQLSvr;
	$SQLLogins = $MySQL.Logins;

	$SysAdmins += foreach($SQLUser in $SQLLogins)
	{
		foreach($role in $SQLUser.ListMembers())
		{
			if($role -match 'sysadmin')
			{
			    Write-Host &quot;SysAdmins found: $($SQLUser.Name)&quot; -ForegroundColor Yellow;
			    $SQLUser | Select-Object `
			     @{label = &quot;SQLServer&quot;; Expression = {$SQLSvr}}, `
			     @{label = &quot;CurrentDate&quot;; Expression = {(Get-Date).ToString(&quot;yyyy-MM-dd&quot;)}}, `
			     Name, LoginType, CreateDate, DateLastModified;
			};
		};
	};
	## - End of Code block

}

## - BUild and open report:
$SysAdmins | Export-Csv -Path 'C:\temp\SQLSysAdminList.csv' -Force -NoTypeInformation;
ii 'C:\temp\SQLSysAdminList.csv';
</pre>
<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2012/02/powershell-quick-list-of-sql-users-with-sysadmin-roles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QuickBlog &#8211; Use PowerShell to submit SQLServicePack job to multiple Server</title>
		<link>http://www.maxtblog.com/2012/01/quickblog-use-powershell-to-submit-sqlservicepack-job-to-multiple-server/</link>
		<comments>http://www.maxtblog.com/2012/01/quickblog-use-powershell-to-submit-sqlservicepack-job-to-multiple-server/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 21:53:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=991</guid>
		<description><![CDATA[This was an interesting discussion in the LinkedIn &#8220;How to Install SQL Service Pack by PowerShell?&#8221;.  I got the chance to create and test this one out. I scratched the previous script I posted trying to show probe a concept, and &#8230; <a href="http://www.maxtblog.com/2012/01/quickblog-use-powershell-to-submit-sqlservicepack-job-to-multiple-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This was an interesting discussion in the LinkedIn &#8220;How to Install SQL Service Pack by PowerShell?&#8221;.  I got the chance to create and test this one out. I scratched the previous script I posted trying to show probe a concept, and ended up creating a new smaller script. Funny!! I created a smaller script!</p>
<p>Well, I just confirmed that&#8217;s possible to submit an unattended SQL ServicePack installer as a job using PowerShell Remoting. I&#8217;m using my Hyper-V Virtual Domain I ran the script from a Windows 7 VM and submitted one job to two servers. I could see the the jobs processing on the server Task Manager.</p>
<p>But, it was tedious? If you&#8217;re a newbie maybe it&#8217;s a little over your head but not impossible. That&#8217;s the intention of PowerShell Remoting, to be able to do these things like this, and I&#8217;m just scratching the surface. Please, Take advantage of these features in PS V2.0, and more enhancements has been done in PS v3.0 with the inclusion of Workflows.</p>
<p>Still, you will need to use PowerShell &#8220;<span style="color: #0000ff;"><strong>Enable-PSRemoting</strong></span> <em><strong>-force</strong></em>&#8221; in all the servers. I know, this may be an issue but you need to configure it on all the servers in order to take advantage of PowerShell Remoting. Now, I&#8217;m creating session on each computer so I can run as jobs, and your credential is Important to be included. All this is done from your desktop, no more running to the server room.</p>
<p>This time I did test the new script using Sessions in PS Remoting:</p>
<pre class="brush: powershell; title: ; notranslate">
## - Get your credential information top connect to servers:
$getCred = Get-Credential 'Domain99\UserName99'
$servers = &quot;Server1&quot;,&quot;Server2&quot;;
$Jobsession = New-PSSession -Computername $servers -Credential $getCred;

## - display the sessions:
$Jobsession

## - Submit jobs to background process on selected servers:
Invoke-Command -Session $Jobsession -AsJob -JobName 'TestBackgroundInstall' `
-ScriptBlock {
new-psdrive -name SQLInstallDrive -psprovider FileSystem -root \\WIN8Server1\install;
cd SQLInstallDrive:;
&amp; ./SQLServer2008R2SP1-KB2528583-x64-ENU.exe /allinstances;
};

## To Display jobs:
get-job

## - To Close PS Sessions and remove variabler:
Remove-PSSession $Jobsession
Remove-Variable Jobsession
</pre>
<p>In the &#8220;<strong>Invoke-Command</strong>&#8220;, the <strong><em>&#8220;-ScriptBlock&#8221;</em></strong> parameter will hold the code you&#8217;re executing on the server as a background job.  Inside the &#8216;-scriptblock { .. }&#8217; parameter, I&#8217;m executing three commands:</p>
<p>1. Creating the PSdrive to the &#8220;Install&#8221; shared folder.<br />
2. Changing directory (this one could be optional).<br />
3. Finally, run the SQLServer2008R2SP1-KB2528583-x64-ENU.exe SQL Service Pack,</p>
<p>This way you&#8217;re not holding the PowerShell Console hostage. You could even make this script more robust. You could add the parameter <em><strong>&#8220;-ThrottleLimit&#8221;</strong></em> to specify the max number of concurrent connections, to minimize the network traffic. This is just a start, this code can be improve a lot.</p>
<div id="attachment_993" class="wp-caption aligncenter" style="width: 1436px"><a href="http://www.maxtblog.com/wp-content/uploads/2012/01/Ask_Cred_1-25-2012-3-11-59-PM1.png"><img class="size-full wp-image-993" title="Ask_Cred_1-25-2012 3-11-59 PM" src="http://www.maxtblog.com/wp-content/uploads/2012/01/Ask_Cred_1-25-2012-3-11-59-PM1.png" alt="" width="1426" height="990" /></a><p class="wp-caption-text">You&#39;ll need to supply your Windows Credentials</p></div>
<div id="attachment_995" class="wp-caption aligncenter" style="width: 1349px"><a href="http://www.maxtblog.com/wp-content/uploads/2012/01/SubmitBackgroundJob_1-25-2012-3-15-56-PM1.png"><img class="size-full wp-image-995" title="SubmitBackgroundJob_1-25-2012 3-15-56 PM" src="http://www.maxtblog.com/wp-content/uploads/2012/01/SubmitBackgroundJob_1-25-2012-3-15-56-PM1.png" alt="" width="1339" height="749" /></a><p class="wp-caption-text">Submitting the job from Windows</p></div>
<div class="mceTemp mceIEcenter"> For more information about PowerShell Remoting, type at the PowerShell Prompt:<br />
<span style="color: #0000ff;"><strong>get-help</strong></span> <strong>About_Remoting</strong> -full<br />
<strong><span style="color: #0000ff;">get-help</span></strong> <strong>Invoke-Command</strong> -full</div>
<p>Check out the TechNet Tip link on PS Remoting:<br />
<a href="http://technet.microsoft.com/en-us/magazine/ff700227.aspx">http://technet.microsoft.com/en-us/magazine/ff700227.aspx</a></p>
<p>Added: Please, check this TechEd 2011 video of my college Don Jones talking about &#8220;Windows PowerShell Remoting: Definitely NOT Just for Servers&#8221;:<br />
<a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fchannel9%2Emsdn%2Ecom%2FEvents%2FTechEd%2FNorthAmerica%2F2011%2FWCL321&amp;urlhash=V-Ec&amp;_t=tracking_disc" rel="nofollow" target="blank">http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/WCL321</a></p>
<p>Of course, there are products out there to help manage/automate your Microsoft security, and service packs.  But you will still need to invest time configuring the application.</p>
<p>Well!! This was a good one.<br />
 <img src='http://www.maxtblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2012/01/quickblog-use-powershell-to-submit-sqlservicepack-job-to-multiple-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell &#8211; Trap cmdlet errors.</title>
		<link>http://www.maxtblog.com/2011/12/powershell-trap-cmdlet-errors/</link>
		<comments>http://www.maxtblog.com/2011/12/powershell-trap-cmdlet-errors/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 01:33:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=970</guid>
		<description><![CDATA[Sometimes working with data can be challenging.  As a SQL Developer, creating ETL solutions, is our responsibility all this data makes it to our users.  Sometime data manipulation might be limited in SSIS, we are force to look for other &#8230; <a href="http://www.maxtblog.com/2011/12/powershell-trap-cmdlet-errors/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes working with data can be challenging.  As a SQL Developer, creating ETL solutions, is our responsibility all this data makes it to our users.  Sometime data manipulation might be limited in SSIS, we are force to look for other alternatives.  In my case, I use PowerShell, and I need a way to trap some import processing errors during the execution of the “<strong><span style="color: #3366ff;">Invoke-SQLcmd</span></strong>” cmdlet.  Then, I will be able to investigate why some on my data wasn&#8217;t making it into my SQL tables.</p>
<p>I try to use PowerShell the &#8220;Try-Catch&#8221; to trap the error but it was wrong implementation to trap the error in the SQL Server PowerShell &#8220;<span style="color: #3366ff;"><strong>Invoke-SQLcmd</strong></span>&#8221; command.  So, How can I trap the command errors?  Well, you can use &#8220;<em><strong>CommonParameters</strong></em>&#8220;, which are an additional set of parameters automatically provided by Windows PowerShell.  In these additional set of parameters you will find the &#8220;<strong><em>-ErrorVariable</em></strong>&#8221; parameter which allow you to stores the error information in a given variable.  The error variable you provide in any cmdlet will be overridden each time the cmdlet execute, unless you add an &#8220;+&#8221; in front of it so it can append to it and collect error information.</p>
<p>For more<br />
Information about all &#8220;<em><strong>CommondParameters</strong></em>&#8220;, execute at the PS prompt:</p>
<pre class="brush: powershell; title: ; notranslate">

Help About_CommonParameters -full
</pre>
<p>Now, my implementation was to use the <em><strong>&#8220;-ErrorVariable</strong></em>&#8221; parameter to trap and save the error message with the SQLquery script that failed. Also, I make sure to the variable to a null value after I saved the results to disk. In my scenario, the data imported could break my SQL query and I want to make sure I can identify these records.</p>
<p>So, I&#8217;m using the ErrorVariable parameter in my &#8220;<span style="color: #3366ff;"><strong>Invoke-SQLcmd</strong></span>&#8221; command.  Here&#8217;s a code snippet sample of it:</p>
<pre class="brush: powershell; title: ; notranslate">
$reccount = 1; $sqlerr = $null;

:

Foreach($item in $Data)
{
:

  $outfile = &quot;C:\ImportError\TSQLQUERY_$($reccount).sql&quot;;
  $SqlQuery =  &quot;Insert into $tablename ($tblfields) values($fldsvalue);&quot;;
  Invoke-Sqlcmd -Database $dbName -ServerInstance $ServerName `
    -Query $SqlQuery -ErrorVariable sqlerr;

  if($sqlerr -ne $null)
  {
     &quot;/*Error Found - on record# [ $reccount ]:&gt; `r`n&quot;+$Error[0] + &quot;*/ `r`n&quot; `
       |  Out-File $outfile -Encoding ASCII;
     $SqlQuery | Out-File $outfile -Encoding ASCII -Append;
     &quot;`r`n /* &quot;+&quot;&quot;.padleft(45,&quot;=&quot;)+&quot; */`r`n&quot; `
       | Out-File $outfile -Encoding ASCII -Append;
     $sqlerr = $null;
  }
   :
  $reccount++;
}
</pre>
<p>Basically, I want to make sure my “<span style="color: #ff0000;">$sqlerr</span>” Error Variable is initialized as $null in both the beginning and after the error have been saved to the output file. Then, we can view later the Error message and the SQL script that error out to later view the output file displaying it in your SSMS or your favorite editor.</p>
<p>Keep in mind, this will not stop the errors from been displayed on screen.  But, you could use another Common Parameter: &#8221; <strong><em>-ErrorAction </em></strong><em>SilentlyContinue</em>&#8221; to prevent displaying the errors.</p>
<p>Sample output  file image:</p>
<p><img class="aligncenter size-full wp-image-976" title="SampleTrap_InvokeSQLcmd_error" src="http://www.maxtblog.com/wp-content/uploads/2011/12/SampleTrap_InvokeSQLcmd_error1.png" alt="" width="998" height="300" />I hope you find this code snippet useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/12/powershell-trap-cmdlet-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell &#8211; Sum items in a CSV file.</title>
		<link>http://www.maxtblog.com/2011/12/powershell-sum-items-in-a-csv-file/</link>
		<comments>http://www.maxtblog.com/2011/12/powershell-sum-items-in-a-csv-file/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 15:22:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=957</guid>
		<description><![CDATA[The fact that PowerShell gives you the ability to a build tasks in many different ways, it&#8217;s sometimes intimidating.  But, you&#8217;ll find the way to improve your coding as time goes.  I try, the best I can, to keep things simple. So, &#8230; <a href="http://www.maxtblog.com/2011/12/powershell-sum-items-in-a-csv-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The fact that PowerShell gives you the ability to a build tasks in many different ways, it&#8217;s sometimes intimidating.  But, you&#8217;ll find the way to improve your coding as time goes.  I try, the best I can, to keep things simple.</p>
<p>So, here&#8217;s another approach on How-To &#8220;<em>Sum</em>&#8221; items in a CSV file:</p>
<p>My Data</p>
<pre class="brush: powershell; title: ; notranslate">
## sbData.csv:
# Date,Item,ItemType,Amount,Company
# 12/12/11,Ben Aipa 8'10,Longboard,1500,BenAipa
# 12/12/11,Walden 9'6&quot;,Longboard,1100,Walden
# 12/13/11,Channel Island 6',Shortboard,800,ChannelIsland
# 12/13/11,Mark Richards 6'8&quot;,Shortboard,750,Surftech
# 12/14/11,Walden 7'6&quot;,Funboard,800,Walden
# - End of CSV file -
</pre>
<p>The request is to sum the amount of the items group by Date and ItemType.  And here&#8217;s the solution:</p>
<pre class="brush: powershell; title: ; notranslate">
## - Working process to Sum amount in a CSV file by grouping columns:
$gdata = Import-csv sbData.csv | Group-Object -Property Date,ItemType;

## - BUild your new object with the sum items:
[Array] $newsbData += foreach($gitem in $gdata)
{
$gitem.group | Select -Unique Date,ItemType, `
@{Name = 'SumAmount';Expression = {(($gitem.group) | measure -Property Amount -sum).sum}}
};

## - Build back the CSV file with the Sum items
$newsbData | Export-Csv NewsbData.csv -NoTypeInformation;
ii NewsbData.csv;
</pre>
<p>So, you can substitute the group items in &#8221; -property &#8220; parameter with the ones you want to be grouped on, then use  the &#8220;<em><strong>Select -unique</strong></em> &#8230;&#8221; to include the grouped items you want to list.  The magic happens when including the  &#8220;<em><strong>Measure</strong></em>&#8221; command against the already grouped items so you can sum the &#8216;Amount&#8217; field.  Now, this code could become a template to sum up items when needed.</p>
<p>The Result:</p>
<pre class="brush: powershell; title: ; notranslate">
# - My CSV new Output data:
# &quot;Date&quot;,&quot;ItemType&quot;,&quot;SumAmount&quot;
# &quot;12/13/11&quot;,&quot;Longboard&quot;,&quot;2600&quot;
# &quot;12/13/11&quot;,&quot;Shortboard&quot;,&quot;1550&quot;
# &quot;12/14/11&quot;,&quot;Funboard&quot;,&quot;800&quot;
# - end of file -
</pre>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/12/MySumItems.jpg"><img class="aligncenter size-full wp-image-967" title="MySumItems" src="http://www.maxtblog.com/wp-content/uploads/2011/12/MySumItems.jpg" alt="" width="1000" height="635" /></a></p>
<p>Happy PowerShelling!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/12/powershell-sum-items-in-a-csv-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QuickBlog &#8211; Finding a value in a PowerShell Hash table &#8211; Simple!!</title>
		<link>http://www.maxtblog.com/2011/12/quickblog-finding-a-value-in-a-powershell-hash-table-simple/</link>
		<comments>http://www.maxtblog.com/2011/12/quickblog-finding-a-value-in-a-powershell-hash-table-simple/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 15:28:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=949</guid>
		<description><![CDATA[For this quick blog, let&#8217;s create a month hash object table containing the number and name of the month.  Then, we are going to query this Hash Table object for a specific month. 1. Creating our Month Hash Table: Notice in this &#8230; <a href="http://www.maxtblog.com/2011/12/quickblog-finding-a-value-in-a-powershell-hash-table-simple/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For this quick blog, let&#8217;s create a month hash object table containing the number and name of the month.  Then, we are going to query this Hash Table object for a specific month.</p>
<p>1. Creating our Month Hash Table:</p>
<pre class="brush: powershell; title: ; notranslate">
$MonthHashTable = @{ `
[int] &quot;1&quot; = &quot;January&quot;; `
[int] &quot;2&quot; = &quot;February&quot;; `
[int] &quot;3&quot; = &quot;March&quot;; `
[int] &quot;4&quot; = &quot;April&quot;; `
[int] &quot;5&quot; = &quot;May&quot;; `
[int] &quot;6&quot; = &quot;June&quot;; `
[int] &quot;7&quot; = &quot;July&quot;; `
[int] &quot;8&quot; = &quot;August&quot;; `
[int] &quot;9&quot; = &quot;September&quot;; `
&quot;10&quot; = &quot;October&quot;; `
&quot;11&quot; = &quot;November&quot;; `
&quot;12&quot; = &quot;December&quot;; `
};
</pre>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/12/FindMonth_HashTableObject.jpg"><img class="aligncenter size-full wp-image-952" title="FindMonth_HashTableObject" src="http://www.maxtblog.com/wp-content/uploads/2011/12/FindMonth_HashTableObject.jpg" alt="" width="860" height="684" /></a></p>
<p>Notice in this example, we&#8217;ve assigned &#8216;Strong-typed&#8217; values to most of the keys (month number) as Integer, and leaving the last three to default to a string data &#8220;<span style="color: #993300;">data type</span>&#8220;.</p>
<p>Keep in mind, in a Hash Table you have Keys, and Values.  So, we are going to search for a &#8216;Key&#8217; in order to get the &#8216;Value&#8217; so we can extract the Month name.</p>
<p>Here&#8217;s the Hash Table Syntax for finding the value using the key:<br />
<span style="color: #0000ff;">$yourHashTable</span>.<strong>Item(</strong> <strong><span style="color: #800000;">[#key#]</span></strong> <strong>)</strong></p>
<p>2. Lets go and Looking for the fourth and eleventh month name:</p>
<pre class="brush: powershell; title: ; notranslate">
## ----------------------------------------
## - Getting &quot;April&quot;:
## - Value stored as Integer for &quot;April&quot;:
$mth = 4;

## - Bad, passing a string value when expecting an Integer
## -&gt; no key found, nothing to return:
$MonthHashTable.Item(&quot;4&quot;);

## - Good, getting month name using Integer value
## -&gt; keys found, a values are returned:
$MonthHashTable.Item(4);
April

$MonthHashTable.Item($mth);
April

## ----------------------------------------
## - Getting &quot;November&quot;:
## - Value stored as Integer for &quot;November&quot;:
$mth = 11;

## - Bad, passing an integer value when expecting a string
## -&gt; no key found, nothing to return:
$MonthHashTable.Item(11);

## - Bad, passing an integer value when expecting a string
## -&gt; no key found, nothing to return:
$MonthHashTable.Item($mth);

## - Value stored as String for &quot;November&quot;:
$mth = &quot;11&quot;;

## - Good, getting month name using String value:
## -&gt; key found, a value is returned:
$MonthHashTable.Item($mth);
November
</pre>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/12/FindMonth_HashTableObject21.jpg"><img class="aligncenter size-full wp-image-954" title="FindMonth_HashTableObject2" src="http://www.maxtblog.com/wp-content/uploads/2011/12/FindMonth_HashTableObject21.jpg" alt="" width="848" height="724" /></a></p>
<p>As the sample show, we need to make sure the variable value must have the proper &#8220;<span style="color: #993300;"><em>data type</em></span>&#8221; so it can find the key.</p>
<p>Happy PowerShelling!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/12/quickblog-finding-a-value-in-a-powershell-hash-table-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLPASS PowerShell Virtual Chapter &#8211; &#8220;Extending T-SQL with PowerShell&#8221; Posted Slides &amp; Scripts..</title>
		<link>http://www.maxtblog.com/2011/12/sqlpass-powershell-virtual-chapter-extending-t-sql-with-powershell-slides-scripts/</link>
		<comments>http://www.maxtblog.com/2011/12/sqlpass-powershell-virtual-chapter-extending-t-sql-with-powershell-slides-scripts/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 20:33:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=934</guid>
		<description><![CDATA[For all whom attended the SQLPASS PowerShell Virtual Chapter &#8211; &#8220;Extending Your T-SQL Scripting with PowerShell&#8221; session on Wednesday November 16th, I finally got it posted here. My sincere Apologies for the long delay in posting my session slides and &#8230; <a href="http://www.maxtblog.com/2011/12/sqlpass-powershell-virtual-chapter-extending-t-sql-with-powershell-slides-scripts/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For all whom attended the<strong> SQLPASS PowerShell Virtual Chapter</strong> &#8211; &#8220;<span style="color: #008080;"><em>Extending Your T-SQL Scripting with PowerShell</em></span>&#8221; session on Wednesday November 16th, I finally got it posted here.</p>
<p>My sincere Apologies for the long delay in posting my session slides and demo scripts.  I thought I lost the material after having a disk drive corruption but I was able to recorver it.</p>
<p>Please, click on the link :&lt; <a title="Download &quot;SQLPASS PVC - Extend T-SQL With PowerShell session" href="https://skydrive.live.com/redir.aspx?cid=7fd7082276c66197&#038;resid=7FD7082276C66197!358&#038;parid=7FD7082276C66197!357" target="_blank">download now</a>&gt;: from SkyDrive. (<em>rename file *.zip.txt to *.zip before extracting</em>)</p>
<p>Don&#8217;t hesitate to contact me if you have any issues downloading it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/12/sqlpass-powershell-virtual-chapter-extending-t-sql-with-powershell-slides-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YES!! Windows Management Framework (WMF/PowerShell) 3.0 CTP2 is here.</title>
		<link>http://www.maxtblog.com/2011/12/yes-windows-management-framework-wmfpowershell-3-0-ctp2-is-here/</link>
		<comments>http://www.maxtblog.com/2011/12/yes-windows-management-framework-wmfpowershell-3-0-ctp2-is-here/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 17:12:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=929</guid>
		<description><![CDATA[YES!!  It&#8217;s another great accomplishment from the Microsoft PowerShell Team.  Just released on December 2nd 2011 this CTP (Community Technology Preview) come with fixes and more enhancements.  Please CHECK out PowerShell ISE, is really showing some progress. Get it here: http://www.microsoft.com/download/en/details.aspx?id=27548 &#8230; <a href="http://www.maxtblog.com/2011/12/yes-windows-management-framework-wmfpowershell-3-0-ctp2-is-here/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>YES!!  It&#8217;s another great accomplishment from the Microsoft PowerShell Team.  Just released on December 2nd 2011 this <strong>CTP</strong> (<em>Community Technology Preview</em>) come with fixes and more enhancements.  Please CHECK out <strong>PowerShell ISE</strong>, is really showing some progress.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/12/ISEv3CTP2look1.png"><img class="aligncenter size-full wp-image-930" title="ISEv3CTP2look1" src="http://www.maxtblog.com/wp-content/uploads/2011/12/ISEv3CTP2look1.png" alt="" width="484" height="315" /></a></p>
<div id="attachment_931" class="wp-caption aligncenter" style="width: 1039px"><a href="http://www.maxtblog.com/wp-content/uploads/2011/12/ISEv3CTP2Customized.png"><img class="size-full wp-image-931" title="ISEv3CTP2Customized" src="http://www.maxtblog.com/wp-content/uploads/2011/12/ISEv3CTP2Customized.png" alt="" width="1029" height="783" /></a><p class="wp-caption-text">PowerShell ISE V3 CTP2 Customizable Themes</p></div>
<p><strong>Get it here</strong>: <a title="WMF PowerShell 3.0 CTP2" href="http://www.microsoft.com/download/en/details.aspx?id=27548" target="_blank">http://www.microsoft.com/download/en/details.aspx?id=27548</a></p>
<p><strong>First thing!!!  READ:&gt;</strong> <span style="text-decoration: underline;"><span style="color: #ff0000; text-decoration: underline;">IMPORTANT!!</span>  <strong><span style="color: #ff0000; text-decoration: underline;">YOU NEED TO UNINSTALL WMF 3.0 CTP1</span></strong>!</span>  <em>Or, suffer the consequences.</em></p>
<p>But, it you&#8217;re one of the few experiencing Windows 8 Preview and using Hyper-V 3.0 then you can create another VM for a clean CTP2 installation experience.  Or, just use the VM shapshot to to back and forth between version.  So, take a pick.</p>
<p>This version comes with some documentation, so make sure to ready it.  Also, don&#8217;t be afraid to submit bug reports at: <a title="PowerShell Connect site" href="https://connect.microsoft.com/PowerShell/" target="_blank">https://connect.microsoft.com/PowerShell/</a>. (you need to have a Live ID)</p>
<p>For example, I just put in a suggestion to include the ability to &#8220;Comment-In&#8221; and &#8220;Comment-Out&#8221; block of code: <a href="https://connect.microsoft.com/PowerShell/feedback/details/711231/ise-v3-need-to-be-able-to-comment-a-series-of-lines-in-a-block-of-code" target="_blank">https://connect.microsoft.com/PowerShell/feedback/details/711231/ise-v3-need-to-be-able-to-comment-a-series-of-lines-in-a-block-of-code</a></p>
<p><em>*Hint*Hint*:  </em></p>
<ol>
<li>When running scripts, I notice there has been changes to how the &#8220;<em>Set-ExecutionPolicy</em>&#8221; behaves.  I&#8217;m used to set my execution policy to &#8220;<em>RemoteSigned</em>&#8220;, but for this version now I had to changed it to<em> &#8220;Unrestricted&#8221;</em>. (more test to be done)</li>
<li>Also, don&#8217;t forget to execute the &#8220;Update-Help&#8221; as soon as you open PowerShell.  This is working for most part.</li>
</ol>
<p>There will be more to come soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/12/yes-windows-management-framework-wmfpowershell-3-0-ctp2-is-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 8 Hyper-V 3.0 &#8211; My Personal 8 Tips for the Newbie</title>
		<link>http://www.maxtblog.com/2011/10/windows-8-hyper-v3-my-personal-tips-for-the-newbie/</link>
		<comments>http://www.maxtblog.com/2011/10/windows-8-hyper-v3-my-personal-tips-for-the-newbie/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 12:47:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=902</guid>
		<description><![CDATA[Well, Here&#8217;s some tips to those who are first timers with Windows 8 Server (or Client) Preview edition.  I have to say, after been using the previous version of Hyper-V, I&#8217;m very happy for what i&#8217;ve seen so far in &#8230; <a href="http://www.maxtblog.com/2011/10/windows-8-hyper-v3-my-personal-tips-for-the-newbie/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Well, Here&#8217;s some tips to those who are first timers with Windows 8 Server (or Client) Preview edition.  I have to say, after been using the previous version of Hyper-V, I&#8217;m very happy for what i&#8217;ve seen so far in Windows 8 Server with Hyper-V 3.0.  As I finally completed updating/rebuilding all my VM&#8217;s for upcoming PowerShell and SQL Servers presentations, I have compiled 8 tips that might help the newbies get started using Microsoft Virtualization Technology.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMmanager.png"><img class="aligncenter size-full wp-image-911" title="VMmanager" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMmanager.png" alt="" width="1072" height="767" /></a></p>
<div id="attachment_922" class="wp-caption aligncenter" style="width: 1083px"><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMconnecttoVM.png"><img class="size-full wp-image-922" title="VMconnecttoVM" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMconnecttoVM.png" alt="" width="1073" height="770" /></a><p class="wp-caption-text">From the Hyper-V Manager console, click on the VM Connect option to work with your VM&#39;s.</p></div>
<h3></h3>
<h3><strong><span style="text-decoration: underline;">Tip #1 &#8211; Memory is important</span></strong></h3>
<h3>Yes, I totally agree with this one.  After I upgraded my memory from 4GB to 8GB, all my VM&#8217;s are working OK.  I have experience giving 1.5GB to a Virtual SQL machine is ideal for development.</h3>
<div id="attachment_912" class="wp-caption aligncenter" style="width: 1191px"><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMmemorySetting.png"><img class="size-full wp-image-912" title="VMmemorySetting" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMmemorySetting.png" alt="" width="1181" height="1038" /></a><p class="wp-caption-text">VM Memory Setting</p></div>
<h3></h3>
<h3><strong><span style="text-decoration: underline;">Tip #2 &#8211; Enabling Hyper-V</span></strong></h3>
<p>First, There&#8217;s some differences between Hyper-V 3.0 server and Client.  But, let me be clear, that every machine might be different.  In my case, I have a 4 year old HP Pavilion dv7-* Entertainment laptop with Virutalization option enabled. I created a dual boot Windows 8 Server and Client version.</p>
<p>On the Windows 8 Server enabling &#8220;Hyper-V&#8221; role using the new &#8220;Server Manager&#8221; Dashboard was easy.  But, in my case, I had to manually enable &#8220;Hyper-V Core&#8221; on my Windows 8 client by turning it &#8220;ON&#8221; in Windows Features.  Here&#8217;s the command:</p>
<p><span style="color: #0000ff;">C:\Dism /online /enable-feature /featurename:Microsoft-Hyper-V</span></p>
<h3></h3>
<h3><strong><span style="text-decoration: underline;">Tip #3 &#8211; Create your Hyper-V 3.0 Virtual Network Switch</span></strong></h3>
<p>This is very Important and one this you need to setup your Virtual Network connections in either Server or Client. Open &#8220;Hyper-V Manager&#8221; and look the &#8220;Virtual Switch Manager&#8221;.</p>
<div id="attachment_913" class="wp-caption aligncenter" style="width: 1117px"><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VirtualNetworkSwitch.png"><img class="size-full wp-image-913" title="VirtualNetworkSwitch" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VirtualNetworkSwitch.png" alt="" width="1107" height="878" /></a><p class="wp-caption-text">Hyper-V Virtual Switch Settings</p></div>
<p>As you can see in my picture, I have a Loopback adapter Virtual Switch (External), and a Wireless Virtual Swtich(Externa) both setup as Legacy Adapters).   These two combination works great when VM&#8217;s talk to each other and, at the same time, have access to the internet for Windows Update.  Keep in mind, you can disable the wireless by going into the VM Settings option, going into the &#8220;Legacy Network Adapter&#8221;, and changing the &#8220;Virtual Switch&#8221; to &#8220;not Connected&#8221;.</p>
<div id="attachment_915" class="wp-caption aligncenter" style="width: 1192px"><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMSettigs1.png"><img class="size-full wp-image-915" title="VMSettigs" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMSettigs1.png" alt="" width="1182" height="881" /></a><p class="wp-caption-text">VM Settings menu - Changing Virtual Switch to &quot;Not Connected&quot;</p></div>
<h3></h3>
<h3><strong><span style="text-decoration: underline;">Tip #4 &#8211; Don&#8217;t need a SAN Storage</span></strong></h3>
<p>FYI. Hyper-V 3.0 will allow you to create your VM&#8217;s practically anywhere.  In my case, I have an External USB 1.o TB Storage drive.  This is good new because you don&#8217;t need a SAN storage unit, and can save Vm&#8217;s outside your Physical server drives.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/LaptopUSBdrive.png"><img class="aligncenter size-full wp-image-916" title="LaptopUSBdrive" src="http://www.maxtblog.com/wp-content/uploads/2011/10/LaptopUSBdrive.png" alt="" width="765" height="601" /></a></p>
<h3></h3>
<h3><strong><span style="text-decoration: underline;">Tip #5 &#8211; Set VM&#8217;s TimeZone correctly</span></strong></h3>
<p>This might be only in my case, but after creating my VM&#8217;s and trying to connect them to join my Virtual Domain Controller, I experience connectivity issues between my VM&#8217;s due to their Time Zones not been the same.  So, If you have a Virtual Domain Controller, make sure both Time Zone machines are the same.</p>
<p>Here&#8217;s an interesting link on &#8220;Time Synchronization in Hyper-V&#8221; (by the &#8220;Virtual PC Guy&#8217;s Blog&#8221;) you may find useful: <a href="http://blogs.msdn.com/b/virtual_pc_guy/archive/2010/11/19/time-synchronization-in-hyper-v.aspx">http://blogs.msdn.com/b/virtual_pc_guy/archive/2010/11/19/time-synchronization-in-hyper-v.aspx</a></p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMTimeZones1.png"><img class="aligncenter size-full wp-image-918" title="VMTimeZones" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMTimeZones1.png" alt="" width="463" height="481" /></a></p>
<h3></h3>
<h3><strong><span style="text-decoration: underline;">Tip #6 &#8211; Learn to use the VM Snapshot Feature</span></strong></h3>
<p>Yes! This feature is a life saver.  It can help you troubleshoot VM issues by you taking the snapshot of a VM machine before doing any irreversible updates that could force you start over to rebuild the machine over.  It&#8217;s perfect when creating multiple scenarios for in test machines and adding descriptions to it.  Also, you can also revert to a previous snapshot, or apply the changes.</p>
<div id="attachment_919" class="wp-caption aligncenter" style="width: 1076px"><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMSnapshot.png"><img class="size-full wp-image-919" title="VMSnapshot" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMSnapshot.png" alt="" width="1066" height="807" /></a><p class="wp-caption-text">List of a server Snapshot showing different stages during a SQL Server Installation</p></div>
<div id="attachment_921" class="wp-caption aligncenter" style="width: 413px"><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMSnapshotDescription1.png"><img class="size-full wp-image-921" title="VMSnapshotDescription" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMSnapshotDescription1.png" alt="" width="403" height="214" /></a><p class="wp-caption-text">Adding a Description to your Snapshot</p></div>
<p>&nbsp;</p>
<p><span style="text-decoration: underline;"><strong>Tip #7 &#8211; Bringing Legacy Microsoft VM to Hyper</strong>-V3</span></p>
<p>If you want to move all your existing VM&#8217;s from: Virtual PC, Windows Virtual PC, and Hyper-V, just remember to uninstall all &#8220;Virtual Components&#8221;, or &#8220;Integration Services&#8221; to prevent any misbehaviour in your VM.  Then, you will be able to install the Hyper-V 3.0 &#8220;Integration Services&#8221; so that Hyper-V can manager your VM&#8217;s services such as: Snapshot, Start, Shutdown, or Save.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMintegrationServices.png"><img class="aligncenter size-full wp-image-923" title="VMintegrationServices" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMintegrationServices.png" alt="" width="650" height="394" /></a></p>
<h4><em>*hint*: I have experience some issues with Windows Servers 2008, and Windows 2003 SP1 after mvoing them to Hyper-V 3.0.  The mouse won&#8217;t work even after installing &#8220;Integration Services&#8221;.</em></h4>
<h3></h3>
<h3><strong><span style="text-decoration: underline;">Tip #8 &#8211; Start using Use PowerShell</span></strong></h3>
<p>Yes! YES! This is your opportunity to start using PowerShell.  You can user the Hyper-V module and start managing your VM&#8217;s.  Also, don&#8217;t forget that PowerShell comes with over 1695 and about  63 Modules.  Keep in mind,  This numbers will varies depending on the enabled Windows features and/or installed Server Applications containing PowerShell modules.</p>
<p>Here&#8217;s some one-liners command you may want to try get the estimate numbers of PowerShell commands and modules:</p>
<p>1. Get total number of available  commands and list their names:</p>
<p><span style="color: #0000ff;">(get-command -Module *).count; (get-command -Module *) | Select name;</span></p>
<p>2. Get total numbers of available (installed) Modules, and list their names:</p>
<p><span style="color: #0000ff;">(get-Module -ListAvailable).count; (get-Module -ListAvailable) | Select name;</span></p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/Windows8PowerShellv34.png"><img class="aligncenter size-full wp-image-910" title="Windows8PowerShellv3" src="http://www.maxtblog.com/wp-content/uploads/2011/10/Windows8PowerShellv34.png" alt="" width="883" height="667" /></a></p>
<p>I hope this information is helpful.  That&#8217;s it for now!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/10/windows-8-hyper-v3-my-personal-tips-for-the-newbie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server PowerShell SMO &#8211; Simple way to Change SQL User Passwords</title>
		<link>http://www.maxtblog.com/2011/10/sql-server-powershell-smo-simple-way-to-change-sql-user-passwords/</link>
		<comments>http://www.maxtblog.com/2011/10/sql-server-powershell-smo-simple-way-to-change-sql-user-passwords/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 18:50:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=896</guid>
		<description><![CDATA[Here&#8217;s a simple PowerShell SMO code that shows you How-To change a SQL user password.  Keep in mind, SMO needs to be installed and the assemblies loaded before using this code. To load SMO, you can: 1. Install the SQLPS Module &#8230; <a href="http://www.maxtblog.com/2011/10/sql-server-powershell-smo-simple-way-to-change-sql-user-passwords/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple PowerShell SMO code that shows you How-To change a SQL user password.  <em>Keep in mind, SMO needs to be installed and the assemblies loaded before using this code</em>.</p>
<p>To load SMO, you can:</p>
<p>1. Install the SQLPS Module (is using SQL Server 2012 &#8220;Denali&#8221;), or Chad&#8217;s Miller <a title="SQLPS Module for SQL Server 2008 / 2008 R2" href="http://sev17.com/2010/07/making-a-sqlps-module/" target="_blank">SQLPS module </a>for SQL Server 2008/R2.</p>
<h5><span style="color: #0000ff;">Import-Module SQLPS -DisableNameChecking</span></h5>
<p>2. Or, Load the SMO Assemblies using the PowerShell V2 &#8220;AddType&#8221; command: (but carefull is you have multiple SQL Server versionsin the same box)</p>
<h5><span style="color: #0000ff;">Add-Type -AssemblyName &#8220;Microsoft.SqlServer.Smo&#8221;</span></h5>
<p>3. Or, use the still reliable the old PowerShell V1 load assemblies line using:</p>
<h5><span style="color: #0000ff;">[reflection.assembly]::LoadWithPartialName(&#8220;Microsoft.SqlServer.Smo&#8221;)</span></h5>
<p>In the following example show how to connect to a SQL Server using both the default Windows Authentication (with high Administrator privileges already set), or SQL Server Authenbtication to later change a user password.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/SQLSMO_ChgPswd.jpg"><img class="aligncenter size-full wp-image-899" title="SQLSMO_ChgPswd" src="http://www.maxtblog.com/wp-content/uploads/2011/10/SQLSMO_ChgPswd.jpg" alt="" width="647" height="520" /></a></p>
<h4><em>*Hint*:</em> <em>If you want to include special characters, you need to use the single qoutes or PowerShell will think that it&#8217;s a variable name.</em></h4>
<p>As you can see,  with just a few line of PowerShell SMO code you can start orchestrating a solution that can be applied to your SQL Server environments.</p>
<p>Just try it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/10/sql-server-powershell-smo-simple-way-to-change-sql-user-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Standalone Windows 8 Server Virtual Machine with SQL Server 2012 CTP3</title>
		<link>http://www.maxtblog.com/2011/10/creating-a-standalone-windows-8-server-virtual-machine-with-sql-server-2012-ctp3/</link>
		<comments>http://www.maxtblog.com/2011/10/creating-a-standalone-windows-8-server-virtual-machine-with-sql-server-2012-ctp3/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 16:05:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://www.maxtblog.com/?p=874</guid>
		<description><![CDATA[Here&#8217;s how I build my version of a standalone workgroup Windows 8 Server Virtual Machine(VM) with SQL Server 2012 (&#8220;Denal;i&#8221;) CTP3. When you create this VM, make sure to give enough memory. How-To create a VM in Hyper-V Manager console: I&#8217;m not &#8230; <a href="http://www.maxtblog.com/2011/10/creating-a-standalone-windows-8-server-virtual-machine-with-sql-server-2012-ctp3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how I build my version of a standalone workgroup <span style="color: #800000;">Windows 8 Server</span> Virtual Machine(VM) with <span style="color: #800000;">SQL Server 2012</span> (&#8220;Denal;i&#8221;) CTP3. When you create this VM, make sure to give enough memory.</p>
<h3><strong><span style="text-decoration: underline;">How-To create a VM in Hyper-V Manager console:</span></strong></h3>
<p>I&#8217;m not going deep on this topic but the Hyper-V Manager GUI it&#8217;s easy to use.  I&#8217;m assuming you already got an *.ISO image of both: Windows 8 Server Preview and SQL Server 2012 CTP3.  If not you&#8217;ll have to find it at Microsoft website and/or your MSDN/Technet subscribtion.</p>
<h4><strong>Before Creating your new Virtual machine:</strong></h4>
<p>Keep in mind, you&#8217;ll need to setup you Hyper-V environment.  Meaning, if you&#8217;re using a laptop and/or a desktop computer (not a server),  still you need to make sure it meets the Hyper-V requirements or it won&#8217;t work.</p>
<p>So, at least you will need to use the &#8220;Virtual Switch Manager&#8230;&#8221; to assist you setting up your virtual network card to use by any VM you create.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperV011.png"><img class="aligncenter size-full wp-image-876" title="HyperV01" src="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperV011.png" alt="" width="1068" height="736" /></a></p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperVVirtualmanager01.png"><img class="aligncenter size-full wp-image-877" title="HyperVVirtualmanager01" src="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperVVirtualmanager01.png" alt="" width="1070" height="743" /></a></p>
<p>Notice, in my environment, I have created three virtual network adapters:</p>
<ol>
<li>Wired Internet</li>
<li>Wireless Internet</li>
<li>Loopback</li>
</ol>
<p>The first two adapters serve my purpose to be able to connect to my physical machine Internet connection so I can do windows update.  The loopback adapter is for my internal network connection to my virtual Domain Controller.</p>
<h4><em>*Hint*: In order to allow your VMs to access your external wireless adapter, you need to enable in &#8220;Server Manager&#8221; the &#8220;Wireless LAN Service&#8221; feature before you create the virtual wireless adapter.</em></h4>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/ServerWirelessLanService.png"><img class="aligncenter size-full wp-image-878" title="ServerWirelessLanService" src="http://www.maxtblog.com/wp-content/uploads/2011/10/ServerWirelessLanService.png" alt="" width="282" height="70" /></a></p>
<p>Now, you are ready to create a New Virtual machine, and just follow the wizard:</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperVNewVirtual.png"><img class="aligncenter size-full wp-image-879" title="HyperVNewVirtual" src="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperVNewVirtual.png" alt="" width="1067" height="739" /></a></p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperVVirtualWizard.png"><img class="aligncenter size-full wp-image-880" title="HyperVVirtualWizard" src="http://www.maxtblog.com/wp-content/uploads/2011/10/HyperVVirtualWizard.png" alt="" width="725" height="557" /></a></p>
<p>The &#8220;New Virtual Machine Wizard&#8221; will help you configured everything you need.   Make sure you create this VM with enough memory.  In my case I assigned 1.5GB of memory.</p>
<h3><strong><span style="text-decoration: underline;">Opening your Virtual Machine Connection:</span></strong></h3>
<p>There&#8217;s two ways to open your VM Connection in your &#8220;Hyper-V Manager&#8221; console:</p>
<ol>
<li>By double-clicking at the actual virtual name.</li>
<li>Or, double-click at the actual virtual machine preview pane at the bottom left side of the &#8220;Hyper-V&#8221; console.</li>
</ol>
<p>Now that your connection GUI is open, it&#8217;s a good time to start doing a VM Snapshot in case you need to go back and troubleshoot in case of problems. Here&#8217;s some pictures on How-To create a VM Snapshot:</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMConnectionSnapshot01.png"><img class="aligncenter size-full wp-image-882" title="VMConnectionSnapshot01" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMConnectionSnapshot01.png" alt="" width="947" height="747" /></a></p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/VMConnectionSnapshot02.png"><img class="aligncenter size-full wp-image-883" title="VMConnectionSnapshot02" src="http://www.maxtblog.com/wp-content/uploads/2011/10/VMConnectionSnapshot02.png" alt="" width="354" height="152" /></a></p>
<p>If a Snapshot box asking to add a Name to your snapshot, go ahead and do it.  This box only comes when there has been changes done to your VM.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/Snapshotname.png"><img class="aligncenter size-full wp-image-884" title="Snapshotname" src="http://www.maxtblog.com/wp-content/uploads/2011/10/Snapshotname.png" alt="" width="403" height="214" /></a></p>
<p>Now, Ready for SQL Installation.</p>
<p><strong><span style="text-decoration: underline;">Installing SQL Server 2012 (&#8220;Denali&#8221;) CTP3:</span></strong></p>
<p>After building the virtual server, if you try to immediately install SQL Server 2012, it won&#8217;t work.  And, when you try to run the setup.exe, you won&#8217;t have access to the &#8220;SQL Server Installation Center&#8221; to view the &#8220;<em>Hardware and Software Requirements</em>&#8221; information.</p>
<h4><span style="text-decoration: underline;"><strong>Check SQL Server Requirements:</strong></span></h4>
<p>So first, you may want to check this link to read about what&#8217;s required to install this new version of SQL Server: <a href="http://msdn.microsoft.com/en-us/library/ms143506(v=SQL.110).aspx">http://msdn.microsoft.com/en-us/library/ms143506(v=SQL.110).aspx</a></p>
<h4><strong><span style="text-decoration: underline;">Need Role(s) and Feature(s):</span></strong></h4>
<p>In order to make my SQL Server installation work, I had to open Windows 8 &#8220;<strong>Server Manager</strong>&#8221; and follow the wizard to do the following steps:</p>
<ol>
<li>Install the Application Server Role (you can add more roles as you need during this process).</li>
<li>Then, you need to add the following features: (again, you can add additional features as needed)<br />
a. Enable the .NET Framework 3.5<br />
b. Enable the PowerShell ISE</li>
</ol>
<p>After doing this steps, then I was able to get the SQL Server setup to work and allow me to start my installation.  Use the VM Connect GUI to allow you to attached the SQL Server  *.ISO image for your VM to start the SQL Server Installation.</p>
<p>I&#8217;m not going to show all the SQL Server installation screens but here&#8217;s to show that I&#8217;m able to proceed with the installation.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/SnapshB4InstallSQLCTP3.png"><img class="aligncenter size-full wp-image-881" title="SnapshB4InstallSQLCTP3" src="http://www.maxtblog.com/wp-content/uploads/2011/10/SnapshB4InstallSQLCTP3.png" alt="" width="899" height="747" /></a></p>
<p>On the previuos picture, notice that I selected most of the features to install except the for the two Distributed Replay services. At the same time, I took a live snapshot of my VM before the actual installation process.</p>
<h3><span style="text-decoration: underline;"><strong>Installation Completed Successfully:</strong></span></h3>
<p>Yes! I got my SQL Server 2012 installed without a glitch!</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/SuccesfullInstallSQLCTP3.png"><img class="aligncenter size-full wp-image-885" title="SuccesfullInstallSQLCTP3" src="http://www.maxtblog.com/wp-content/uploads/2011/10/SuccesfullInstallSQLCTP3.png" alt="" width="1168" height="971" /></a></p>
<h3><span style="text-decoration: underline;"><strong>Testing SQL PowerShell:</strong></span></h3>
<p>Now, I immediately testing the PowerShell SQLPS module. I was so excited that forgot to do something first.  Here&#8217;s my result of my first try:</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/Win8VMonHyperVWithSQL2K12.png"><img class="aligncenter size-full wp-image-886" title="Win8VMonHyperVWithSQL2K12" src="http://www.maxtblog.com/wp-content/uploads/2011/10/Win8VMonHyperVWithSQL2K12.png" alt="" width="1798" height="1152" /></a></p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/LoadingSQLPSErrors.png"><img class="aligncenter size-full wp-image-887" title="LoadingSQLPSErrors" src="http://www.maxtblog.com/wp-content/uploads/2011/10/LoadingSQLPSErrors.png" alt="" width="1144" height="798" /></a></p>
<p>Yes! I forgot to set my &#8220;<strong>Set-ExecutionPolicy</strong>&#8221; to &#8220;<strong>RemoteSigned</strong>&#8220;, then close and reopen my Windows Console.  I also I was able to SQLPS.exe from SSMS Database option just to test that there&#8217;s no errors.  So, everything works at least for now.</p>
<p>Ooops! Except for PowerShell ISE.  Yes! If you try to do an &#8220;Import-Module SQLPS -DisableNameChecking&#8221; then you get an error:</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/ISE-error.png"><img class="aligncenter size-full wp-image-888" title="ISE error" src="http://www.maxtblog.com/wp-content/uploads/2011/10/ISE-error.png" alt="" width="974" height="623" /></a></p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/ISE-Error_ConsoleOK.png"><img class="aligncenter size-full wp-image-889" title="ISE Error_ConsoleOK" src="http://www.maxtblog.com/wp-content/uploads/2011/10/ISE-Error_ConsoleOK.png" alt="" width="930" height="714" /></a></p>
<p>Don&#8217;t Worry!  PowerShell ISE is not the only editor.  You can still use Notepad to create/modify your script(s).  Or, just try downloading one of the free community editors from: SAPIEN, and PowerGUI just to name a few.</p>
<p>To test SQLPS I use the following command line:</p>
<h4><span style="color: #0000ff;">Invoke-SQLcmd -database ReportServer -Query &#8220;Select top 3 * from dbo.DBUpgradeHistory</span></h4>
<h3><strong><span style="text-decoration: underline;">Final comments:</span></strong></h3>
<p>I know I may have skip some steps but the bulk on How-To create Window 8 Server VM in shown in this blog.  One important thing to keep in mind, these are still Community Technologies Preview (CTP) and it will change.</p>
<p>So, Don&#8217;t be afraid to try it!  This is why we have the ability to create Virtual Machines in our own developement machines.  Again, take advantage of Hyper-V.</p>
<p>The opportunity we have is to learn from them, assist giving feedback, and MOST IMPORTANT, it help us to stay ahead in upcoming technologies.</p>
<p>Enjoy, Learn, and Collaborate!</p>
<h2><strong><span style="color: #800000;">Bonus!!&#8230; Bonus!!</span></strong></h2>
<p>If you want a HACK to fix the PowerShell ISE that here it is: (Hack provided by one of our PowerShell MVP&#8217;s &#8211; Joel &#8220;Jaykul&#8221; Bennett<br />
<a href="http://HuddledMasses.org" target="_blank">http://HuddledMasses.org</a><br />
<a href="http://PowerShellGroup.org" target="_blank">http://PowerShellGroup.org</a><br />
)</p>
<ol>
<li>Go to you x:\Windows\System32\WindowsPowerShell folder (make sure to access this folder &#8220;As an Administrator&#8221; or it won&#8217;t work)</li>
<li>Create a blank text filename: powerShell _ise.exe.config (Yes! this file extension is &#8220;.config&#8221;)</li>
<li>Then, add the following XML lines, and save the file when done:</li>
</ol>
<h6><em><span style="color: #800000;">(Updated: 10/26/2011 &#8211; I missed the &#8220;runtime&#8221; section)</span></em></h6>
<p><span style="color: #800000;">&lt;configuration&gt;<br />
&lt;startup useLegacyV2RuntimeActivationPolicy=&#8221;true&#8221;&gt;<br />
&lt;supportedRuntime version=&#8221;v4.0&#8243; /&gt;<br />
&lt;/startup&gt;<br />
&lt;runtime&gt;<br />
&lt;loadFromRemoteSources enabled=&#8221;true&#8221;/&gt;<br />
&lt;/runtime&gt;<br />
&lt;/configuration&gt;</span></p>
<p>Reopen PowerShell ISE and try to use the &#8220;<span style="color: #0000ff;">Invoke-SQLcmd</span>&#8221; command.</p>
<p><a href="http://www.maxtblog.com/wp-content/uploads/2011/10/PowerShellISEhack1.png"><img class="aligncenter size-full wp-image-893" title="PowerShellISEhack" src="http://www.maxtblog.com/wp-content/uploads/2011/10/PowerShellISEhack1.png" alt="" width="1156" height="839" /></a></p>
<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.maxtblog.com/2011/10/creating-a-standalone-windows-8-server-virtual-machine-with-sql-server-2012-ctp3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

