Going Crazy with Windows Azure PowerShell tonight

You’re all invited to attend FLPSUG online meeting on “Windows Azure PowerShell cmdlet” with MS Windows Azure Evangelist – Scott Klein‏.

To register go here: http://flpsugmay2013online.eventbrite.com/

Don’t miss it! It will be both fun and informative.

Here’s an example of what has been trending in twitter recently.  Please notice that’s all been on Windows Azure.

Some of yesrterday (05/20/2013) “Window Azure PowerShell” links:

Automating Windows Azure Infrastructure Services (IaaS) Deployment with PowerShell – See more at:
http://blogs.technet.com/b/yungchou/archive/2013/05/20/automating-windows-azure-infrastructure-services-iaas-deployment-with-powershell.aspx?utm_source=feedburner&utm_medium=twitter&utm_campaign=Feed%3A+YungChouOnHybridCloud+%28Yung+Chou+on+Hybrid+Cloud%29#sthash.ibQad0aX.dpuf

Overview of Microsoft #WindowsAzure #Powershell for automated #Cloud Services:
http://mountainss.wordpress.com/2013/05/20/overview-of-microsoft-windowsazure-powershell-for-automated-cloud-services/

PowerShell script to migrate SharePoint to Azure IaaS
http://spiffy.sg/it-pros/powshell-script-to-migrate-sharepoint-to-azure-iaas/

PowerShell script to get username and password for FTP from Microsoft Azure publish settings
http://karl-henrik.se/powershell-script-to-get-username/?utm_source=buffer&utm_medium=twitter&utm_campaign=Buffer&utm_content=buffer08a3d

Application Management-Example-Deploying a Service to Your Private Cloud (Part 1)
http://blogs.technet.com/b/privatecloud/archive/2013/04/03/application-management-example-deploying-a-service-to-your-private-cloud-part-1.aspx

Application Management-Example-Deploying a Service to Your Private Cloud (Part 2)
http://blogs.technet.com/b/privatecloud/archive/2013/04/05/application-management-example-deploying-a-service-to-your-private-cloud-part-2.aspx

Azure does Powershell too
http://www.scarydba.com/2013/05/20/azure-does-powershell-too/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+HomeOfTheScaryDba+%28Home+of+the+Scary+DBA%29

Additional MSDN videos at Channel 9: MSDN Channel 9
http://channel9.msdn.com/WindowsAzure

If you missed last week Microsoft Virtual Academy on “Windows Azure for IT Professionals Jump Start”  check the recorded videos:
https://www.microsoftvirtualacademy.com/liveevents/Windows-Azure-for-IT-Professionals?CR_CC=200206715

Sample VHD migration image PowerShell script by David Aiken:

Here’s some of my personal notes from the “Windows Azure for the IT Pro – Jump Start”

Great Sessions today under the Microsoft Virtual Academy O “Windows Azure for IT Professionals Jump Start” with David Tesar and David Aiken today.

Azure AD
1. Azure AD thru a Windows Azure VM spin off.
2. Run on Windows Azure IaaS.
3. Network Gateway need to be defined before building the VM.
4. DC VM need an addition drive to store all the NTDS databases files.
5. DC Wizard NTDS section the folders need to point to the additional VM drive (don’t pick C:\).
6. Under the directory service panel, need to add a new site to point to the Windows Azure AD site.

AD to Windows Azure AD – Synch
1. Cloud Only / No integration
2. Directory Synch – using member server (no on DC) and only one way (can’t go back). Use “DirSynch”
3. Directory and Single Sign-On

Migrating VM (VHD) to Window Azure
1. you can use a Disk2VHD. Hint: Have one network card and set to use DHCP.
2. It will copy VHD size type from Dynamic to Fixed Disk format.
3. Cloud act as a Networking boundaries.
4. Only VHD format allowed (no VHDX).
5. Don’t use Static IP Address and remove PowerShell remoting.
6. Changes to system configuration: memory, network adapters, etc.

And, there’s more I wasn’t able to attend.

Don’t be left out!  Learn PowerShell now.

Posted in Uncategorized | Comments Off

PowerShell v3 fun with Get-Help and Out-GridView

PowerShell comes loaded with help documentation, and in PowerShell V3 this documentation is updated via the internet.  Now, lets have some fun with the Get-help and the updated Out-Gridview command.

The Out-Gridview cmdlet have a ‘-passthru‘ parameter that gives you the ability to select items from the popup window and the pass these values to the next command.  This is neat!!

Copy/paste the code below into your PS console to load the “Get-HelpTopics“:

Function Get-HelpTopics{
## - Have fun using PassThru switch to select item(s): (PowerShell V3 feature)
$HelpNames = (GET-HELP About_*) | select name;
foreach($i in ($HelpNames | Select name | Out-GridView -PassThru))
{
	$i | Select @{Label = 'Topic Selected'; Expression = {$_.Name}};
	Get-Help $i.Name -ShowWindow;
}
};

Then, to execute type “Get-HelpTopics” and the list of topics will be displayed in a popup window.

Hold the ‘Ctrl’ key to select/mark the topics you want to read, then click the ‘OK’ button when done.

As you can see you will get a series of popup windows documentation you can move around and read about PowerShell. At the same time you are seeing how helpful is the use of the ‘-passthru‘ parameter in the ‘Out-Gridview’, and the ‘-ShowWindow‘ parameter in the ‘Get-help’.

This is a fun way to start learning PowerShell.
** This is a Windows PowerShell V3 script **

Posted in PowerShell, Resources | Comments Off

Our revamped FLPSUG site is up …

Thanks to our team member David Cobb has been able to help shape our new FLPSUG website.  Please signup, become a member, and don’t miss our great speakers.

http://www.flpsug.com/

There’s more to come!

Posted in PowerShell | Comments Off

Palm Beach IT User Group – “PowerShell for the Administrator – All About The Language”

Thank once again to the Palm Beach IT User Group for having my presenting live my session “PowerShell for the Administrator – All About The Language” on May 14th evening.   http://itportalregulus.blogspot.com/

The group had the opportunity to see the evolution from a single one-liner command, to a script file, a function, and a brief taste to a module.  Also, the scripts supplied has an abundant of code snippets that can be reused.

Also, giving example of reusing and modifying a community script (Thx, Jefferey Hicks for his contributions) so you can make it your own.

Here’s some reference links: http://jdhitsolutions.com/blog/2012/02/create-html-bar-charts-from-powershell/ and http://jdhitsolutions.com/blog/2011/12/friday-fun-drive-usage-console-graph/

Special Thanks to Sapien Technology for providing some books to giveaway and to Plurasight for the free one month online subscription.

Here’s the end result.  A function that check the machine disk space, build an HTML file with a graph and send an email thru your live.com SMTP server.

function Get-DiskUsageHTMLGraph{
Param(
	[array] $ComputerNames,
	[string] $ReportPath = "c:\Temp\HTML_DiskSpace.html",
	[boolean] $ViewReport,
	[boolean] $SendEmail,
	[Array] $SendTo
)

	## - Set variable (no function):
	$htmlTitle='Server Drive(s) Report'

## - Configuring the HTML CSS Style sheet for the HTML code: (#FFFFCC)
## - When using Here-String/Splatting you must begin in the first position.
## - The use of Tab is invalid.
$head = @"

 $($htmlTitle)

"@

	## - Define the HTML Fragments as an Array type, add the header and title object:
	[Array] $HTMLfragments = $null; $HTMLfragments += $head;
	$HTMLfragments+="</pre>
<h1>Server Disk Space</h1>
<pre>

";

	## - Build WMI Disk information object and group results by ComputerNames:
	$SystemNames = get-wmiobject -Class Win32_logicaldisk -computer $ComputerNames `
		| Group-Object -Property SystemName;

	## - This is the graph character code:
	 [string] $gCode = [char] 9608;

	## - Loop through each computer object found and create html fragments:
	ForEach ($System in $SystemNames)
	{
	    ## - Get the System name:
		$HTMLfragments+="</pre>
<h2>$($System.Name)</h2>
<pre>
"

	    ## - Create an html fragment for each system found:
	     $html = $System.group `
		| Where-Object {$_.DriveType -notmatch '5|2'} | Sort-Object -Property Name `
		| Select-Object `
			SystemName, @{Label = "DriveID";Expression={$_.Name}}, `
			VolumeName, FileSystem, DriveType, `
	        @{Label="DiskSizeGB";Expression={"{0:N}" -f ($_.Size/1GB) -as [float]}}, `
	        @{Label="FreeSpaceGB";Expression={"{0:N}" -f ($_.FreeSpace/1GB) -as [float]}}, `
	        @{Label="PercFree";Expression={"{0:N}" -f ($_.FreeSpace/$_.Size*100) -as [float]}}, `
			@{Label="Low				if(($_.FreeSpace/$_.Size*100) -le '15') `
				{ `
					"- Critical -"; `
				} `
				Else `
				{ `
					$null; `
				}; `
			  }}, `
		     @{Name="";Expression={ `
		       $UsedPer = (($_.Size - $_.Freespace)/$_.Size)*100; `
		       $UsedGraph = $gCode * ($UsedPer/2); `
		       $FreeGraph = $gCode * ((100-$UsedPer)/2); `
		       "xltFont color=Redxgt{0}xlt/FontxgtxltFont Color=Greenxgt{1}xlt/fontxgt" `
					-f $usedGraph,$FreeGraph; `
	     }} | ConvertTo-Html -Fragment;

	    ## - Replacing replace the tag place holders: (Jefferey's hack at work)
	    $html=$html -replace 'xlt','
	    ##  - Add the Disk information results to the HTML fragment:
	     $HTMLfragments+=$html;

	    ## - Insert a line break for each computer it find:
	     $HTMLfragments+="
";
	}

	## - Add a footer to HTML code:
	$footer=("
<em>Report run {0} by {1}\{2}<em>" -f (Get-Date -displayhint date),$env:userdomain,$env:username)
 $HTMLfragments+=$footer

 ## - Write HTML code to a file on disk:
 ConvertTo-Html -head $head -body $HTMLfragments | Out-File $ReportPath;

 if($ViewReport -eq $true)
 {
 ii $ReportPath;
 }

 if($SendEmail -eq $true)
 {
 ## - Setting the information for hotmail:
 $MyEmailAcct = "UserX@live.com";
 $MyPassword = ConvertTo-SecureString '$myPassword!' -AsPlainText -Force;
 $MyCredentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $MyEmailAcct,$MyPassword
 [Array] $emaillist = @('User1@gmail.com','UserX@live.com');

 ## - OR, send it as a body message in the email:
 $GetError = $null;
 Send-MailMessage `
 -From 'MySysAdmin-DoNotReply@MySysAdmin.com' `
 -To $SendTo `
 -Subject "Diskspace Information for the date - $((Get-Date).ToString("MMddyyyy, HH:MM"))" `
 -BodyAsHtml ([string] (ConvertTo-Html -head $head -body $HTMLfragments)) `
 -SmtpServer 'smtp.live.com' `
 -Credential $MyCredentials `
 -UseSsl `
 -Port 587 `
 -ErrorAction SilentlyContinue `
 -ErrorVariable GetError;

 if($GetError -ne $null)
 {
 $date = (get-Date).ToString("MMddyyyy_HHMMss");
 "Sender: $($getCred1.UserName) `r`n $GetError" | `
 Out-File -FilePath "C:\Temp\log\emailerror_$date.txt";
 };
 };
};

Sample results for email to live.com:

Sample Browser:

Here’s the zipped presentation link:

Posted in PowerShell, Windows 2012, Windows 8 | Comments Off

SQL Server Pro April issue – SMO and PowerShell Article is out!

Take a look at my SQL Server SMO article “Using SQL Server Management Objects with PowerShell” in the “SQL Server Pro” April magazine is available now on the internet: http://www.sqlmag.com/article/windows-powershell/sql-server-managment-objects-powershell-144832

Sample Article Section

Posted in PowerShell, SQL Server | Comments Off

Orlando IT Pro Camp Keiser University 3/23/2013 – Presentation

Here’s the “Getting Started with Windows 8 PowerShell” presentation plus one sample script to get you started.

Topic description:  This is an introduction session on how to work with PowerShell 3.0 in Windows 8.  I will cover find PowerShell, how to create your PowerShell shorcuts, updating PowerShell help documentation, and briefly covering the some of the enhancements in the ISE editor.

Click on the following link:

Thanks and keep participating with the IT Community!

Posted in Hyper-V, PowerShell, Resources | Comments Off

Don’t worry – FLPSUG website under construction

It’s long overdue to our the Florida PowerShell User Group website to be update to something modern.  So, we are doing some reconstruction and using DotNetNuke as our new CMS.

Please be patient! In the meantime you can connect to my blog page where I’m be posting the progress and new upcoming thing in our FLPSUG group.

Thank you for your support.

Posted in PowerShell | Comments Off

Orlando Code Camp 2013 – PowerShell sample code…

Saturday March 16th, 2013

First, Thanks to the organizers for having me speak about PowerShell and the gift they gave to all the speakers.  Also, Thanks to all the sponsor’s and all whom attended my PowerShell sessions:

1. PowerShell Working with PSObjects.

2. PowerShell working with XML.

Here’s the zip file with both presentation and sample code for download:

Please don’t hesitate to contact me if you have any questions.

It was a pleasure to participate in this event.

Posted in Events, PowerShell | Comments Off

Quickblog on PowerShell Here-String/Splatting simple formatting

Sometime is nice to find simple samples that can make life easy. Here’s a quick sample on how you can use this string manipulation to make it readable. Also, I included a way to dynamically create a PowerShell variable from an existing (it may be useful for someone) just as a proof-of-concept.

In this sample I’m going to create a T-SQL script and display it in my PowerShell console. First, let’s create some variables that will be use to replace some values in our string:


## - Dynamically creating a variable with a value:
$SubstituteVariable = "SQLDatabase";
New-Variable $SubstituteVariable -Value "Developer";

$Tablename = "AddressBook";

The above code will create three PowerShell variable but we are end up using only the $SQLDatabase and the $Tablename in our T-SQL script.

The next few PowerShell code will show you a simple ways to initialize a string variable holding the T-SQL scripts.

1. One-liner sample – All acceptable except when using complex Multi-line T-SQL Scripts.


## [1] - Normal string one liner:
$SQLquery = "Select [firstname], [lastname] from [$SQLDatabase].[dbo].[$Tablename]";
$SQLquery;

2. Using Here-String/Splatting, you can change the above sample and make it a multi-line string. This still is a One-liner, and it use the tab in front of the column names. *note: In PowerShell V3.0 the tab will be ignore but in PowerShell V2.0 it will work OK.


## [2] - Using Here-String/Splatting.  This string contains manual tabs done in and editor the it was copy/paste to the console: (bug in V3 console only.  ISE works.)

$SQLquery1 = @"
Select
	[firstname],
	[lastname]
  from [$SQLDatabase].[dbo].[$Tablename]
"@;

$SQLquery1;
Write-Host "$SQLquery1" -ForegroundColor 'Yellow';

3. The last Here-String sample we are using the .NET ‘-f’ string formatter which will allow you to replace the values for {0} and {1} place holder. In this sample code inside the string i’m hard coding tab as `t (tick symbol plus t) which in this case it works OK in both PowerShell V2 and V3:


## [3] - Using Here-String/Splatting with .NET '-f' formatting:
              $SQLquery2 = @"
Select
`t[firstname],
`t[lastname]
  from [{0}].[dbo].[{1}]
"@ -f $SQLDatabase, $tablename;

Write-Host "$SQLquery2" -ForegroundColor 'Cyan';

4. When using a PowerShell editor (ISE or others) an invalid Here-String variable PowerShell will give an error if you try to use tabs on each line of the code: (can’t use white space in editor with Here-String)

[tab] $x = @”
[tab] Testing
[tab] Testing
[tab] “@;

Basically, Here-String variable works great when you want to store a multi-line string but have some caveats:

1. PowerShell v3 console only. Manual tabs are ignored.
2. When using splatting (@”..”@) the @” can begin in any column position but the terminating “@ ends on the beginning of the new line. See sample #3.
3. When using a PowerShell editor Whitespaces in a Here-String block of code are not allowed.

Posted in PowerShell, SQL Server | Comments Off

Sarasota IT Pro Camp 2013 – PowerShell presentation…

Once again, another great Saturday IT Pro event at Keiser University in Sarasota, Florida.  It was awesome to see some great speakers giving their sessions, and I got to meet Pinal Dave which is pretty well known in the SQL Server Community Worldwide.  See below picture (Me and Pinal Dave).

Microsoft IT Pro  Evangelist Blain Barton put together a great Windows Azure session with Herve Roggero (Windows Azure MVP). See below picture.

Thank You all for attending my PowerShell Working with .NET PSObject session.  Here’s is my full presentation with all the PowerShell scripts I meant to cover.  Please feel free to try them out.  During our session I was able to cover only one of the three Excel PowerShell sample.

Thank You Kieser University for having us!

Posted in PowerShell | Comments Off