background preloader


Facebook Twitter

70-410 Installing and Configuring Windows Server 2012: PowerShell commands for the MCSA 70-410 Microsoft Exam. PowerTip: Import a PowerShell Module from a Shared Location - Hey, Scripting Guy! Blog. PowerShell 2.0 remoting guide: Part 12 – Using CredSSP for multi-hop authentication. PowerShell V4 – PipelineVariable Common Parameter. The big new feature in Windows PowerShell 4.0 is Desired State Configuration however there are a number of other minor features one of which is a new common parameter called PipelineVariable.

PowerShell V4 – PipelineVariable Common Parameter

This parameter allows you to store the current pipeline object into the variable specified by the name you provide. This capability comes in handy when, in the process of executing commands in the pipeline, information is lost due to transformations on the objects flowing down the pipeline. For example, take the following case: Note in this output that the FileInfo objects output by Get-ChildItem got replaced with MatchInfo objects in the pipeline. About_Object_Creation. About_Functions_Advanced_Parameters. Emit-XML - Windows PowerShell Blog. I was writing a demo yesterday and needed a quick and dirty way to generate some XML so I wrote the function below.

Emit-XML - Windows PowerShell Blog

This highlights a couple of changes that are coming up in CTP3 that I thought I would preview. 1) The keyword "cmdlet" is going away and we'll just have "function". Notice that now you can specify the [Parameter()] attribute on parameters. When you do that, we treat the function like a cmdlet.2) Here-strings can now NEST! Look at how simple the code becomes when you do this. The first Here-String starts the XML document with a "<Object>". PowerTab - Home. Huddled Masses. Powershell collection. PowerShell and external commands done right // blog.edgylogic. Windows PowerShell is a massive step up from the VBScript horror used to manage Windows systems (I have no idea how people wrote websites with it without going mental).

PowerShell and external commands done right // blog.edgylogic

One of the things that annoyed me to no end though was how there seemed to be black magic involved when trying to make PowerShell execute external commands, i.e. not PowerShell cmdlets. Writing a PowerShell module in C#, Part 1: The basics. In this series we will cover the basics of building a Windows PowerShell binary module using C#.

Writing a PowerShell module in C#, Part 1: The basics

In the first part of the series we will build a module with just one cmdlet called Get-Salutation that will resemble the traditional “Hello World” example. We will use Visual Studio 2013 since it includes the reference assemblies for System.Management.Automation–the root namespace for Windows PowerShell–for Microsoft .Net Framework 4.0. Microsoft has not released a PowerShell 4.0 SDK with reference assemblies using Microsoft .NET Framework 4.5 at this moment. If you are planning to support Windows PowerShell 2.0 then you will need to download the Windows PowerShell 2.0 SDK from Microsoft Visual Studio 2013 Express for Windows Desktop version can also be used. Open Visual Studio and create a new project from the File menu: Select the Visual C# from the installed Templates list and then pick Class Library since compiled modules in PowerShell are in DLL format:

About_Functions_Advanced_Parameters. Arrays - Powershell adding values together. Dynamic ValidateSet in a Dynamic Parameter - Windows PowerShell tips from the field. A colleague of mine needed a way to have a parameter accept only a specific set of paths.

Dynamic ValidateSet in a Dynamic Parameter - Windows PowerShell tips from the field

I told him this can be accomplished easily with the ValidateSet decoration on the parameter, but he then explained that what the actually needed, is to have the set dynamically defined by the sub folders in the current location, instead of a pre-defined set. This sent me out on a journey to explore the dynamic parameter world. The result of that journey, and the answer to his request is the example function below: WMI Reference. WMI (Windows Management Instrumentation) is available on all Windows systems.

WMI Reference

You can use WMI to locally or remotely query information about a computer and change settings. WMI Classes are organized into namespaces. To use WMI, you will need to know the exact name of the WMI Class you would like to query. Common WMI Classes are found in the namespace section “root/CIMV2″, but there are many other namespace locations with additional WMI classes. Browse the WMI Reference root/CIMV2root/default Additional Resources. Converting CSV to Excel File. PowerShell can easily create CSV files using Export-Csv, and if Microsoft Excel is installed on your system, PowerShell can then have Excel convert the CSV file to a native XLSX Excel file.

Converting CSV to Excel File

Here is some sample code. It uses Get-Process to get some data, then writes the data to a CSV file. Export-Csv uses -UseCulture to make sure the CSV file uses the delimiter your local Excel installation expects. Share what I know or discovered when working with Windows PowerShell. The Lonely Administrator. IT Notes from the Powertoe – Tome Tanasovski. Powershell - Difference between PSObject, Hashtable and PSCustomObject. Use Copy-Property to Make it Easier to Write, Read,and Review Scripts - Windows PowerShell Blog. Dennis Verwiej is doing some great PowerShell work over at his blog Just PowerShell It at .

Use Copy-Property to Make it Easier to Write, Read,and Review Scripts - Windows PowerShell Blog

Recently he posted a blog entry Import Citrix Published Application in which he Imports a CSV file (previously exported) and then calls a few APIs to recreate the published application. If you at the code (in the middle of this blog entry), it the vast bulk of it is a series of lines setting properties before calling the API. I find that this is quite common - I end up writing tons of mind-numbing housekeeping code. Because there is so much of it, it is often hard to tell whether it is right or not. For instance, did you get all the properties set or did you forget a couple? Why not leverage the special capabilities of PowerShell to make this problem go away? You have to deal with the situation of what to do if you try to set a property that doesn't exist. Powershell: How to get get date-1 formatted mm-dd-yyyy? PowerShell One-Liners: Collections, Hashtables, Arrays and Strings. The way to learn PowerShell is to browse and nibble, rather than to sit down to a formal five-course meal.

PowerShell One-Liners: Collections, Hashtables, Arrays and Strings

In his continuing series on Powershell one-liners, Michael Sorens provides Fast Food for busy professionals who want results quickly and aren't too faddy. Part 3 has as its tasty confections Collections, Hashtables, arrays and strings. This series is in four parts: This is part 3 Notes on Using the Tables A command will typically use full names of cmdlets but the examples will often use aliases for brevity. Most tables contain either 3 or 4 columns: a description of an action; the generic command syntax to perform that action; an example invocation of that command; and optionally an output column showing the result of that example where feasible. For clarity, embedded newlines (`n) and embedded return/newline combinations (`r`n) are highlighted as shown.

Custom objects default display in PowerShell 3.0. April 13, 2012 In PowerShell 3.0 we can now create new custom objects using a hash table.

Custom objects default display in PowerShell 3.0

PS> [PSCustomObject]@{ One = 1 Two = 2 Three = 3 Four = 4 Five = 5 } One : 1 Two : 2 Three : 3 Four : 4 Five : 5 Behind the scenes, PowerShell creates a hash table and wraps it a PSCustomObject. It is way faster than using the New-Object cmdlet and it also provides consistency, while maintaining backwards compatibility. Community: VMware vSphere™ PowerCLI. LucD notes - My PowerShell ramblings. Beyond Export-Csv: Export-Xls - LucD notes.

Warning: this post has no “virtual” content ! This time I post a function that allows you to export your data to a “real” spreadsheet (XLS format) instead of a CSV file. The reason for posting this function was a series of threads in the PowerCLI Community by Suresh. Over several threads he has been collecting scripts that create various reports on his vSphere environment. PowerShell Code Repository. Don't underestimate the power of ToString(IFormatProvider) Windows PowerShell Tip: Formatting Dates and Times. Here’s a quick tip on working with Windows PowerShell. These are published every week for as long as we can come up with new tips. If you have a tip you’d like us to share or a question about how to do something, let us know.

Formatting Dates and Times Having recently returned from a vacation in Europe, one of the Scripting Guys was reminded of the following fact: just because Americans do something, that doesn’t mean the rest of the world does that very same thing, or at least not in the very same fashion. This is true when it comes to putting ice in drinks; it’s also true when it comes to formatting dates and times. For example, in the US we use a 12-hour clock. The same sort of thing is true when it comes to calendar days. PERF-02 Consider trade-offs between performance and readability · Penflip. Performance is not the only reason you write a script. If a script is expected to deal with ten pieces of data, a 30% performance improvement will not add up to a lot of actual time. StreamReader.Peek Method (System.IO) Get-MailboxReport.ps1/Get-MailboxReport.ps1 at master · cunninghamp/Get-MailboxReport.ps1.

About_Parameters. About_Functions_Advanced_Parameters. Richard Siddaway's Blog. The April 2015 WMF 5.0 preview brings new functionality in the shape of cmdlets for working directly with the clipboard.