• Using PowerShell OData Provider Module for OneGet and PowerShellGet

    After playing with OneGet and PowerShellGet for some time now I wanted to dive into the OData feed that both new PowerShell v5 preview features are using.

    Let me first summarize OneGet and PowerShellGet.

    OneGet is a new way to discover and install software packages from around the web. With OneGet, you can:

    • ·Manage a list of software repositories in which packages can be searched, acquired, and installed
    • · Search and filter your repositories to find the packages you need
    • · Seamlessly install and uninstall packages from one or more repositories with a single PowerShell command

    This first version of OneGet installs and searches software from Chocolatey repositories.  Support of additional repositories will come in subsequent versions.

    PowerShellGet is a new way to discover, install, and update PowerShell Modules.  New in WMF 5.0 Preview May 2014, PowerShellGet contains a set of cmdlets that enable users to interact with an online module gallery.Instead of having to search through CodePlex, GitHub, various blogs, and TechNet Script Center for all the PowerShell Modules you want, you can use Find-Module to search through an online Gallery

    Both use an OData feed, Open Data Protocol (OData) is a data access protocol initially defined by Microsoft. The protocol was designed to provide standard CRUD access to a data source via a website. If you want to learn more about OData just go to wikipedia.

    Now we know, we can access the OneGet and PowerShellGet repositories using an OData feed we can use the PowerShell OData Explorer. With the 'OData Explorer' PowerShell application we can browse the OData Services. After downloading and unzipping the OData Explorer we need to add the two OData Services from OneGet and PowerShellGet in the ODataServices.csv file.

    PowerShell OData Explorer

    image

    image

    Name, uri
    NetFlix,    "http://odata.netflix.com/Catalog"
    Northwind,  "http://services.odata.org/Northwind/Northwind.svc/"
    TechEd2010, "http://odata.msteched.com/sessions.svc/"
    WorldCup,   "http://www.openligadb.de/Webservices/OData.svc/"
    StackOverflow, "http://odata.stackexchange.com/stackoverflow/atom"
    SuperUser, "http://odata.stackexchange.com/superuser/atom"
    ServerFault, "http://odata.stackexchange.com/serverfault/atom"
    "Meta StackOverflow", "http://odata.stackexchange.com/meta/atom"
    Locations, "http://ogdi.cloudapp.net/v1/dc"
    Chocolatey, "http://chocolatey.org/api/v2/"
    Nuget, "http://www.nuget.org/api/v2/"
    PowerShellget, "https://msconfiggallery.cloudapp.net/api/v2/"

    Open the .\View-OData.ps1 PowerShell script and start browsing.

    image

    You can browse the Chocolatey or NuGet OData feed for the OneGet Packages or for the PowerShell Modules you can browse the PowerShelGet OData feed.

    image

    After browsing through the OneGet and PowerShellGet OData repositories would not it be cool if we can “just” navigate those OData feeds like we do with our other PowerShell Providers?

    OData PowerShell provider

    This can be done using the PowerShell OData Provider Module. The OData PowerShell provider allows you to mount OData feeds as drives in your powershell session. This enables simple and intuitive access to the catalogs, collections, and entities in the feed using the same cmdlets you use for working with files. Download, unzip and install the PowerShell OData Provider and get started navigating your OneGet and PowerShellGet OData feed just like any other PowerShell Provider.

    001
    002
    003
    004
    005
    006
    007
    008
    009
    010
    011
    012
    013
    014
    015
    016
    017
    018
    019
    020
    021
    import-module OData

    #Get-Help on OData queries
    get-help about_OData_Query

    #Create an new OneGet Drive
    New-PSDrive -Name OneGet -PSProvider OData -Root "http://chocolatey.org/api/v2/"

    #Go to OneGet Drive
    cd OneGet

    #Search for latest 7zip package
    get-childitem OneGet:/packages -orderby Version -filter "Title eq '7zip'" -top 1

    #Create an new PowerShelGet Drive
    New-PSDrive -Name PowerShellGet -PSProvider OData -Root "https://msconfiggallery.cloudapp.net/api/v2/"

    #Search top PowerShell Module downloads from PowerShellGet Repository
    get-childitem PowerShellGet:/packages | 
       
    where-object {$_.Islatestversion -eq "$true"} | 
       
    select-object name, @{Label="Downloads";Expression= {[int]$_.Downloadcount}}| sort Downloads -Descending

    image

    Have fun browsing those PowerShellGet and OneGet OData feeds using the PowerShell OData Provider Module.

  • What is my in PowerShell Profile?

    This week Ed Wilson (Hey Scripting Guy) shares information about what people have in their Windows PowerShell profile.

    Interested to know what I’ve in myPowerShell profile? Check the following blog post called  “What’s in Your PowerShell Profile? Microsoft PFEs' Favorites

    Go update your Profile!

  • OpsMgr Program Managers on Twitter

    I guess you already know I’m pretty active on Twitter but since recently an number of OpsMgr (Program) Managers have joined the Twittersphere. You can now start following them on Twitter and ask them to improve your favorite products Winking smile

    Joseph Chan (Principal Program Manager

    Daniele Muscetta (Program Manager)

    Daniel Savage (Principal Program Manager)

    Liz Kim (Program Manager)

    Sacha Dawes (Business Manager)

    For your convenience I also created a Twitter List for the OpsMgr Program Managers

    If I’m someone missing please let me know.

    See you on Twitter Smile

  • PowerShell Grid Widget Helper

    I already blogged about the new PowerShell Grid Widget which came with the release of UR2 for System Center 2012 R2 where we included updates for the Widgets which allow you to create richer dashboard visualization within Operations Manager.

    If you look at the Walkthrough I created, there is a part where you need to create the PowerShell script that is being used for the PowerShell Grid Widget.

    The creation of the PowerShell script was not as straight forward as I would liked it to be. Would not  it be great if you could just have a PowerShell function where you would input your normal PowerShell script and which would generate the script needed for the PowerShell Grid Widget on the fly?

    I created a function that creates the script for the PowerShell Grid Widget with only a limited number of parameters.

    Let’s walk through a scenario.

    Scenario:
    Create a PowerShell Grid Widget for the top 10 OpsMgr Error eventlogs on the server where you have the console running in the last 24 hours.

    You would normally first start with a PowerShell script that retrieves the top 10 OpsMgr Error eventlogs on the Server where you have the Console running for the last 24 hours.

    Get-EventLog -LogName "Operations Manager" -After ((Get-Date).AddHours(-24))| where-object {$_.Entrytype -match "Error"} | Select-Object EventId,Source,Message | Group-Object EventId | Select-Object * -ExpandProperty Group | Select-Object count, EventId, Message -Unique | Sort-Object Count -Desc | Select-Object -first 10

    This would result in the following:

    image

    After we created the script we need to “store” our “normal” PowerShell script in a scriptblock and pass this to our new Show-PSGridWidgetCode helper Function and finally pipe the result to the clipboard so we can copy the script to the Console.

    $scriptblock = {Get-EventLog -LogName "Operations Manager" -After ((Get-Date).AddHours(-24))| where-object {$_.Entrytype -match "Error"} | Select-Object EventId,Source,Message | Group-Object EventId | Select-Object * -ExpandProperty Group | Select-Object count, EventId, Message -Unique | Sort-Object Count -Desc | Select-Object -first 10 } Show-PSGridWidgetCode -scriptblock $scriptblock -id Message | clip

    image

    image

    Result:

    image

    If you want to start playing with the new PowerShell Helper Function Show-PSGridWidgetCode you need to save the following script as PowerShellGrid.ps1

    # --------------------------------------------------- # Script: D:\PowerShellGrid_v0.3.ps1 # Version: 0.4 # Author: Stefan Stranger # Date: 05/19/2014 21:19:49 # Description: PowerShell Grid Widget Helper Function # Comments: With the latest OM2012 UR2 update new Dashboard Widgets have been added. # This helper function helps with the creation of the PowerShell script code needed Grid Widget # Links: http://blogs.technet.com/b/stefan_stranger/archive/2014/04/28/new-powershell-grid-widget-walkthrough.aspx # Know issues: # - First object in returned array will be used as ID property [solved] # - If a property of an object has multiple values this will not displayed correctly [solved] # Changes: [04-30-2014]: Added new Id Parameter. This should be an unique property of the objects # [05-19-2014]: Added string type to all output objects # Disclaimer: # This example is provided “AS IS” with no warranty expressed or implied. Run at your own risk. # **Always test in your lab first** Do this at your own risk!! # The author will not be held responsible for any damage you incur when making these changes! # --------------------------------------------------- Function Show-PSGridWidgetCode { <# .Synopsis Create Script code for use in new OM12R2 UR2 PowerShell Grid Widgets. .DESCRIPTION The output of this function can be copied to the Operations Manager Console to create the script code for creating the new PowerShell Grid Widgets. .EXAMPLE Show-PSGridWidgetCode -scriptblock {Get-Service | Select Name, Status} This command show the script code needed to create a PowerShell Grid Widget showing the Windows NT Services properties Name and Status on the machine where the console is running. You can copy the output to the console to have a head start creating the new Widget. PS C:\Scripts\PS> Show-PSGridWidgetCode -scriptblock {Get-Service | Select Name, Status} -Id "Name" $inputobject = Get-Service | Select Name, Status foreach ($object in $inputobject) { $dataObject = $ScriptContext.CreateInstance("xsd://foo!bar/baz") $dataObject["Id"] = ($object.Name).ToString() $dataObject["Name"] = ($object.Name).ToString() $dataObject["Status"] = ($object.Status).ToString() $ScriptContext.ReturnCollection.Add($dataObject) } #> [CmdletBinding()] Param ( # Inputobject parameter [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$false, Position=0)] [scriptblock]$scriptblock, # Name parameter [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$false)] [string]$id ) $properties = ((&$scriptblock | Get-Member -MemberType Properties).name) #Find properties with a collection of objects foreach ($property in $properties) { $property = $property -join "," $testherestring = @" `$dataObject["$property"] = [String](`$object.$property) "@ [string]$total += "$testherestring`n" } $script = @" `$inputobject = $scriptblock foreach (`$object in `$inputobject) { `$dataObject = `$ScriptContext.CreateInstance("xsd://foo!bar/baz") `$dataObject["Id"] = [String](`$object.$id) $total `$ScriptContext.ReturnCollection.Add(`$dataObject) } "@ $script }

    After saving the script you need to dot source the script (start the script like this . .\PowerShellGrid.ps1) (dot space dot)

    Now you can call the Show-PSGridWidgetcode Function from within PowerShell. I also added help for the Function.

    PS C:\Scripts\PS\OM2012\PowerShellGridWidget> help Show-PSGridWidgetCode -full
     
    NAME
        Show-PSGridWidgetCode
       
    SYNOPSIS
        Create Script code for use in new OM12R2 UR2 PowerShell Grid Widgets.
       
    SYNTAX
        Show-PSGridWidgetCode [-scriptblock] <ScriptBlock> -id <String> [<CommonParameters>]
       
       
    DESCRIPTION
        The output of this function can be copied to the Operations Manager Console to create the
        script code for creating the new PowerShell Grid Widgets.
       
     
    PARAMETERS
        -scriptblock< ScriptBlock>
            Inputobject parameter
           
            Required?                    true
            Position?                    1
            Default value               
            Accept pipeline input?       false
            Accept wildcard characters?  false
           
        -id <String>
            Name parameter
           
            Required?                    true
            Position?                    named
            Default value               
            Accept pipeline input?       false
            Accept wildcard characters?  false
           
        <CommonParameters>
            This cmdlet supports the common parameters: Verbose, Debug,
            ErrorAction, ErrorVariable, WarningAction, WarningVariable,
            OutBuffer, PipelineVariable, and OutVariable. For more information, see
            about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
       
    INPUTS
       
    OUTPUTS
       
        -------------------------- EXAMPLE 1 --------------------------
       
        PS C:\>Show-PSGridWidgetCode -scriptblock {Get-Service | Select Name, Status}
       
       
        This command show the script code needed to create a PowerShell Grid Widget showing the
        Windows NT Services properties Name and Status on the machine where the console is running.
        You can copy the output to the console to have a head start creating the new Widget.
        PS C:\Scripts\PS> Show-PSGridWidgetCode -scriptblock {Get-Service | Select Name, Status} -Id "Name"
             $inputobject = Get-Service | Select Name, Status
             foreach ($object in $inputobject)
             {
                 $dataObject = $ScriptContext.CreateInstance("xsd://foo!bar/baz")
                 $dataObject["Id"] = ($object.Name).ToString()
                             $dataObject["Name"] = ($object.Name).ToString()
                 $dataObject["Status"] = ($object.Status).ToString()
                 $ScriptContext.ReturnCollection.Add($dataObject)
             }
       
       
       
       
       
       
    RELATED LINKS

    The ID parameter is used for the property that is being used as the unique key that is used in the PowerShell Grid Widget.

    Another example for retrieving SCOM Alerts with some filter criteria.

    $scriptblock = { Get-SCOMAlert -Criteria "ResolutionState = 0 AND Severity = 2 AND IsMonitorAlert = 1 AND (Owner <> 'Stefan' OR Owner IS NULL)" | Select Name, Severity, Priority, TimeRaised, ResolutionState } Show-PSGridWidgetCode -scriptblock $scriptblock -id Name | clip

    image

    Disclaimer:
    This example is provided “AS IS” with no warranty expressed or implied. Run at your own risk.
    The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of Microsoft.

    **Always test in your lab first**  Do this at your own risk!! The author will not be held responsible for any damage you incur when making these changes!

  • TechEd North America 2014 OpsMgr Content

    TechEd North America is provides technical education, product evaluation, and community resources to plan, architect, deploy, manage and secure a connected enterprise. The brightest and most skilled technology professions meet to increase their technical expertise through deep hands-on technical learning, sharing of best practices and interaction with Microsoft and a variety of industry experts and their peers.

    Here is an overview of all currently available content about System Center Operations Manager.

    Building Highly Effective Dashboards in Microsoft System Center 2012 R2 Operations Manager

    This session covers the brand new innovations in the Operations Manager dashboard infrastructure that allows you to build custom dashboards for any audience.

    Overview and Enhancements in Microsoft System Center 2012 R2 Operations Manager

    This session provides an overview of the most stable enterprise monitoring product available today and the new innovations that arrived in R2 and since. This session also features a panel discussion with members of the System Center Product Group.

    Microsoft System Center 2012 R2 Operations Manager: Mastering Historical Monitoring Data

    Many monitoring metrics can be used to analyze your infrastructure. Want to know how user activities impact your LOB applications? Need to plan future capacity? Think of moving to the cloud? There is no reason to allow blind guessing where knowledgeable decision can be made.

    Effective Capacity Planning of Your Infrastructure Resources with Microsoft System Center 2012 R2…

    The information you need to make the right choices about how you plan capacity for your private and public cloud infrastructure is at your fingertips in the data that you collect with Operations Manager. All you need to know is how to best utilize the Operations Manager datawarehouse, reporting, dashboarding.

    Monitoring SQL Server with Microsoft System Center 2012 R2 Operations Manager

    Take a deep dive into monitoring Microsoft SQL Server with System Center 2012 R2 Operations Manager, System Center 2012 R2 Advisor and protection with System Center 2012 R2 Data Protection Manager. This session is focused on the application SQL Server and how we can keep it in tip top condition.

    Extending Microsoft System Center 2012 R2 Operations Manager

    This session covers how Operations Manager as a platform has been extended with System Center Advisor to provide Operational Intelligence about customers’ environments by capturing their operational/machine data into a big data store in Azure.

  • Interesting announcements during TechEd North America 2014

    I don’t know if you have noticed but we are this week hosting our TechEd North America 2014 event in Houston, Texas.

    TechEd North America is Microsoft’s premier technology conference for IT Professionals and Enterprise Developers, providing the technical education, product evaluation, and community resources to plan, architect, deploy, manage and secure a connected enterprise.

    While not being present on TechEd I tried to follow some of the interesting announcements made. These are the ones I found most interesting.

    Operations Manager Announcements:

    • Microsoft System Center Advisor – Limited Public Preview.
      System Center Advisor is an online service that analyzes installations of Microsoft server software. Advisor collects data from your installations, analyzes it, and generates alerts that identify potential issues (such as missing security patches) or deviations from identified best practices with regard to configuration and usage. Advisor also provides both current and historical views of the configuration of servers in your environment.

      This new preview we are introducing an new Dashboard based on HTML5 and we introduce Intelligence Packs. We even have a gallery which contains these “intelligence packs” which contain rich knowledge and visualizations for capacity planning, security, diagnostics, and configuration assessment.

      System Center Advisor – Limited Preview gathers data from your on-premise installation and provides rich intelligence. There is no hardware, software, or applications to install, manage or upgrade – everything is cloud-based.

    Sign up here: https://preview.systemcenteradvisor.com/

    Azure Announcements:

    PowerShell Announcements:

    This new package installs exclusively on Windows 8.1 and Windows Server 2012 R2. 

    PowerShellGet is a new way to discover, install, and update PowerShell Modules.

    If you have not yet downloaded or installed WMF 5.0 Preview May 2014 you should do it now.

    I already downloaded and installed the preview and it’s so cool to be able to discover and install new PowerShell modules.

    image

    image

    And while this was not an official announcement Jeffrey Snover introduced PowerShell DSC for Linux.
    image

    How cool is this? Smile

    In case you missed some of the interesting new from TechEd I suggest you go to our Channel 9 video channel and start watching some of the great sessions.

    I already suggest you watch the following sessions on Channel 9:

    Windows PowerShell Unplugged with Jeffrey Snover

    Come learn PowerShell the way PowerShell was meant to be learned—exploring Windows from the console. In this session, Distinguished Engineer Jeffrey Snover starts with the Get-Help cmdlet and shows you the tools and techniques to teach yourself PowerShell. Jeffrey’s contention is that most people still haven’t realized the power of what was delivered in PowerShell V1 so advanced users are likely to learn as much as day zero beginners.

    Channel 9 Live: Windows Azure Pack Automation

    Symon Perriman with Charles Joy

    Channel 9 Live: The Differentiated IT Professional

    Rick Claus with Jeffrey Snover, Distinguished Engineer

    Channel 9 Live: Microsoft Azure with Mark Russinovich

    Rick Claus with Mark Russinovich, Technical Fellow.

    Windows PowerShell Best Practices and Patterns: Time to Get Serious

    Based on results from the 2013 Scripting Games and a summer-long community engagement, this session presents the practices and patterns that the Windows PowerShell community has identified as the most important for creating stable, performant scripts and tools.

    Let’s start with those first Smile

    Have fun!