ive got a powershell secret
TRANSCRIPT
![Page 1: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/1.jpg)
I've got a PowerShell Secret: Putting a GUI on your scripts
Microsoft ServicesPremier Field Engineering
Welcome.Microsoft Services helps businesses around the world maximize their investment in Microsoft products and technologies.
![Page 2: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/2.jpg)
2
Why GUI?Business IntelligenceArchitectureHow ToCall to Action
OBJECTIVE
Understand how to apply XML, XAML, WPF and PowerShell to create an attractive and functional user interface
![Page 3: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/3.jpg)
3
Graphical User Interface (GUI)
![Page 4: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/4.jpg)
Tooling Up
What You'll need
.NET Framework 4
PowerShell (and ISE)
Visual Studio 2013 (or Visual Studio Express 2013)
![Page 5: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/5.jpg)
Tooling Up Scripting with Windows PowerShellhttp://technet.microsoft.com/en-us/library/bb978526.aspx Understanding Event Driven Programming - 23http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners/Understanding-Event-Driven-Programming-23 XPath Tutorialhttp://www.w3schools.com/xpath/default.asp
![Page 6: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/6.jpg)
6
WPF & XAML
Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications.
Extensible Application Markup Language (XAML) is an XML-based markup language that is used to implement an application's appearance declaratively. It is typically used to create windows, dialog boxes, pages, and user controls, and to fill them with controls, shapes, and graphics…
![Page 7: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/7.jpg)
7
How To…Let’s Build It
Drag picture to placeholder or click icon to add
![Page 8: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/8.jpg)
8
Building the Interface
To create interface fire up Visual Studio and create a new WPF project. File > New > Project
![Page 9: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/9.jpg)
9
Building the Interface
![Page 10: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/10.jpg)
Loading the Dialog
[CmdletBinding()]Param( [Parameter(Mandatory=$True,Position=1)] [string]$XamlPath) [xml]$Global:xmlWPF = Get-Content -Path $XamlPath #Add WPF and Windows Forms assembliestry{ Add-Type -AssemblyName PresentationCore,PresentationFramework,WindowsBase,system.windows.forms} catch { Throw "Failed to load Windows Presentation Framework assemblies."} #Create the XAML reader using a new XML node reader$Global:xamGUI = [Windows.Markup.XamlReader]::Load((new-object System.Xml.XmlNodeReader $xmlWPF)) #Create hooks to each named object in the XAML$xmlWPF.SelectNodes("//*[@Name]") | %{ Set-Variable -Name ($_.Name) -Value $xamGUI.FindName($_.Name) -Scope Global }
![Page 11: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/11.jpg)
11
What’s in a Name?
<Label Name="Label1" Content="Label" HorizontalAlignment="Left" Margin="68,38,0,0" VerticalAlignment="Top" Width="197"/> <Button Name="Button1" Content="Button" HorizontalAlignment="Left" Margin="307,41,0,0" VerticalAlignment="Top" Width="75"/>
![Page 12: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/12.jpg)
12
Putting it Altogether
![Page 13: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/13.jpg)
Wire an Event
#EVENT Handler $button1.add_Click({ $Label1.Content = "Hello World"})
![Page 14: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/14.jpg)
Launching the Window
#Launch the window$xamGUI.ShowDialog() | out-null
![Page 15: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/15.jpg)
Fire the Script
Set-ExecutionPolicy -ExecutionPolicy UnrestrictedSet-ExecutionPolicy : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution policy for the default (LocalMachine) scope, start Windows PowerShell with the "Run as administrator" option. To change the execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser".
Kick off your HelloWorld script: .\HelloWorld.ps1
![Page 16: Ive got a powershell secret](https://reader037.vdocuments.us/reader037/viewer/2022102811/5882e9ba1a28ab33258b7c27/html5/thumbnails/16.jpg)
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION
Contact
Chris ContePremier Field Engineer(813) [email protected]
www.microsoft.com/microsoftservices