background preloader

PowerShell Code Repository

PowerShell Code Repository

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. Ultimately he wanted to have a spreadsheet where each report would be stored on a worksheet. PowerShell has the very handy Export-Csv cmdlet to create CSV files but afaik nothing for creating XLS files That’s when I decided to “pimp” my XLS creating function I already had to something more suited for general use. The function uses Excel through a COM object. Update June 16th 2010: the function has a new parameter -ChartType which allows the addition of a chart on the worksheet. Update November 2nd 2010: a complete overhaul of the function The script Annotations Line 112-117: The function tests if the XLS file exists or not.

Resources and Q&A for PowerShell People Windows CMD Commands LucD notes - My PowerShell ramblings PowerShell Magazine Pearltrees Custom objects default display in PowerShell 3.0 | Shay Levy April 13, 2012 In PowerShell 3.0 we can now create new custom objects using a hash table. 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. Another benefit of using PSCustomObject over New-Object is property order. PS > [PSCustomObject]@{One=1;Two=2;Three=3} One Two Three --- --- ----- 1 2 3 PS > New-Object PSObject -Property @{One=1;Two=2;Three=3} One Three Two --- ----- --- 1 3 2 Notice that when the new PSCustomObject is returned, all of its properties are displayed in the console. We can also define the properties of the type that will be displayed by default with the formatting cmdlets.

ISESteroids – A Revolutionary PowerShell ISE Add-On If you love the built-in ISE editor that ships with PowerShell 3.0 and 4.0, but you were missing some professional editor capabilities, then ISESteroids add them for you. It is a commercial PowerShell module that seamlessly integrates with the ISE editor, written by PowerShell MVP Tobias Weltner (me). The primary goal of ISESteroids was to keep the beautiful simple UI, and not turn the editor into something as complex as the control panel of a nuclear power plant. Let me take you on a quick walk-through! (Click on a screenshot to view larger image) Installation ISESteroids are no separate application. Simply get yourself a trial copy here: Once you unpacked the .zip file, you get a folder called “ISESteroids”. Loading ISESteroids To launch ISESteroids, start the PowerShell ISE editor, then enter this: Visual Helpers ISESteroids adds green and blue squiggle lines. Click on a squiggle to find out about the problem in the ISE status bar.

LESS « The Dynamic Stylesheet language 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. 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. Many actions in PowerShell can be performed in more than one way. This is a multi-part series of PowerShell reference charts.

Lee Holmes -dot- Com PylonsHQ - Home Powershell: How to get get date-1 formatted mm-dd-yyyy? Richard Siddaway's Blog Saw a post about WmiMonitorID that intrigued me If you use the WmiMonitorID: PS> Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID | select -f 1 You get a number of properties returned as an array of numbers. if you look at the property with Get-CimClass they unsigned 16 bit integers Name : ManufacturerName Value : CimType : UInt16Array Flags : Property, ReadOnly, NullValue Qualifiers : {MAX, read, WmiDataId} ReferenceClassName : Probably the easiest way to deal with them is a very simple function and calculated fields function Convert-ArrayToName { param ($array) ($array | foreach { [char][byte]$_} ) -join '' The function Convert-ArrayToName accepts an array. Call the function in a calculated field to convert the numeric array to a string – repeat for all relevant properties. Run the code and becomes Active : True Manufacturer : GSM ProductCode : 598F SerialNumber : 304NDJX51788 UserFriendlyName : 22EA63 WeekOfManufacture : 4 YearOfManufacture : 2013