2. Next generation command line shell Processes objects instead of plain text Large set of built-in commands Consistent command parser Scripting language Designed for managing .NET objects Provides a consistent environment for using cmdlets Supports complex tasks without making simple tasks more complex What is it?
3. Built on .NET Underlying objects are .NET Extensible via cmdlets, providers, & host applications Targeted at IT professionals Supported by the latest server products An astonishing amount can be accomplished without any programming TechNet Script Center has hundreds of resources What is it? (cont.)
29. Creating Cmdlets From an administrative Visual Studio command prompt navigate to your output directory and install your assembly Gotcha: On a 64-bit system you’ll need to use the 64-bit version of InstallUtil.exe
30. Creating Cmdlets Launch a new instance of PowerShell View the registered snap-ins: Get-PSSnapIn –Registered Register the snap-in: Add-PSSnapIn
31. Creating Cmdlets Export the current console: Export-Console Include the exported file in your project Set it to always copy to the output directory
32. Creating Cmdlets In the project properties set the debug action to start powershell.exe In the command line arguments specify your console export file using the –PSConsoleFileflag
34. Hosting PowerShell Create a new windows forms application Add a reference to System.Management.Automation and your snap-in project
35. Hosting PowerShell In the form use a RunspaceConfiguration instance to add your snap-in, then create and open the runspace
36. Hosting PowerShell Using the runspace create and invoke a pipeline Remember that Get-Proc is returning a collection and not individual items!
37. PowerShell 1.0 Included in Windows Server 2008 Separate download for Windows XP SP2, Windows Server 2003, & Windows Vista PowerShell 2.0 Included in Windows 7 & Windows Server 2008 R2 RC available for Windows XP SP3, Windows Server 2003 SP2, Vista SP1, & Windows Server 2008 Where do I get it?
Shells have historically executed commands or utilities and presented results as textCmd.exe is the shell on windowsFew built-in commands, large variety of external utilities
You can filter by verb
You can filter by noun
Applications found in your path are available in PowerShellOutput from executables becomes a full-fledged object in PowerShell
Anything can be navigable using PowerShell providers!Even the registry!
SQLPS.exe, which comes with SQL Server 2008, is a custom PowerShell hostIt adds its own provider for navigating objects in SQL Server instances
The things returned by providers are itemsYou can use the –Item commands to work with them directlyIn this case when we get the subtext item we see that it is a Database type from the SMO library
Like everything else there are simple commands for filtering, looping, and sortingThose commands have simple aliasesFilter using whereSelect a new object from an existing object using selectLoop using foreach – notice that your have to ‘return’ something at the endTypical comparison operators like =, <, > aren’t used for parsing reasons
Creating a virtual machine using Hyper-V
Twitter!
It may be easier to believe now, but there is a lot you can do with PowerShell without even opening Visual Studio.