Monday, December 23, 2013

Microsoft Virtual Academy: PowerShell M05

Today I continue forward on my goal of completing Microsoft's Virtual Academy's PowerShell 3.0 training.
(http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start?o=3276#?fbid=aVs9FfAH2DJ)
(rewritten based on my notes available here: https://drive.google.com/file/d/0B1fwreWrAZioUWpaeFNSTFVXUEU/edit?usp=sharing)

Module 5 "Te pipeline:deeper" consists of 3 video segments totaling ≈ 45 minutes along with a PowerPoint of 12 slides.

The focus of this segment is on the pipeline ( | )

As briefly mentioned in past segments the pipeline allows us to pass objects along a string of cmdlets. The pipeline has four (4) ways to be used:

  1. ByValue
  2. ByPropertyName
  3. Customized properties
  4. Parenthetical
First and most common use is through the ByValue. In order to use ByValue we need to know the following: type of object we sending and if the receiving cmdlet can accept it.  To determine the type of our object we use get-member (gm).  Know to validate the receiving cmdlet we run a get-help [cmdlet].  There are two (2) things we are looking for in the help file.  First, if any parameters accept pipeline input and second if any parameters accept our object type.  

Example: Get-Service | Stop-Service
  1. Determine object type: 
    • Get-Service | gm
    • Results: TypeName: System.ServiceProcess.ServiceController
  2. Verify receive cmdlet will accept
    • Get-Help stop-service -full
      • If using v3 use -showWindow and utilize the search feature
    • Verify accept pipeline input: true (.., ByValue,..)
    • Verify input value is sending object type
      • -InputObject <ServiceController[]>
Hint:  if the nouns match most likely will work.


Next we move to the ByPropertyName.  Works very similar to ByValue but is more forgiving.  We follow the same process of verify.  This process works on the concept of a property of sending object matching a parameter in receiving cmdlet.


Example: Get-Service | Stop-Process
  1. Determine object type: 
    • Get-Service | gm
    • Results: TypeName: System.ServiceProcess.ServiceController
  2. Verify receive cmdlet will accept
    • Get-Help stop-process -full
    • Verify accept pipeline input: true (.., ByValue,..)
    • Verify input value is sending object type
      • -InputObject <Process[]>
        • Not the same type so now we look for ByPropertyName
      • -Name <String[]>
        • Will accept input from sending object's property name and process based on that
So what if ByValue and ByPropertyName don't work?  We can create a custom property.  This is accomplished by creating a custom column (calculated property).  With a custom property are goal is to meet the ByPropertyName process.  In the example below and in segment we try to send ADComputer to Get-Service.

Command used:  @{name=’[propertyname]’;expression={$_.[property]}}

Example: Get-ADComputer -filter * | Get-Service -name bits

  1. Determine object type: 
    • Get-ADComputer | gm
    • Results: TypeName: Microsoft.ActiveDirectory.Management.ADComputer
  2. Verify receive cmdlet will accept
    • Get-Help Get-Service -full
      • ByValue: -InputObject <ServiceController[]> - No Go
      • ByPropertyName: -ComputerName (for systems), -Name (for services)
        • We want to use the -ComputerName and not -Name, this is where custom property comes in
  3. Map ADComputer -Name to -ComputerName
    • @{name=’ComputerName’;expression={$_.name}}
  4. Verify Object Property
    • Get-ADComputer | gm
      • Should now see a property called ComputerName

Finally we use Parenthetical when all else has failed us.  Command process what is in parenthesis first.

For this example we want to pull all BIOS details for all ADComputers.

Example: Get-ADComputer –filter * | get-WMIObject –class win32bios

  1. Determine object type: 
    • Get-ADComputer | gm
    • Results: TypeName: Microsoft.ActiveDirectory.Management.ADComputer
  2. Verify receive cmdlet will accept
    • Get-Help Get-WMIObject -full
      • Notice there is no pipeline support
As we see WMIObject does not support pipeline.  To work around this we use -ExpandProperty.  -ExpandProperty will expand a single property into a string object. There are two ways to accomplish this dependent on version you are running.

Command used: Get-adcomputer –filter * | select –ExpandProperty name

If we run this through gm we find object type is no a string.

  • v2 and v3
    • Get-wmiobject –class  win32_bios –ComputerName (Get-adcomputer –filter * | select –ExpandProperty name)
  • v3 only
    • Get-wmiobject –class  win32_bios –ComputerName (Get-adcomputer –filter *).name
That wraps up segment 5.  I hope to have segment 6 up next week but dependent on the holidays and work it may not be up until Mid-January. 

I hope everyone has Happy Holidays.

Friday, December 20, 2013

Holiday IT Poem

'Twas the week before Christmas
And all through SpiceWorks
There were plenty of tickets
Put in from dumb jerks.
Their computers weren't working
Or so they all said
But the IT folks knew
Users are brain-dead
Still every ticket was logged
Every problem looked at
Encountering every user
And pictures of their cats
There was a printer jam
And one with no ink
One had no paper
And someone clogged the sink
That shouldn't be IT
That we all know
But the ticket still came in
So a plumbing I will go
As the weekend draws near
I just impatiently wait
It's almost Saturday
And won't that be great!
My presents are bought
My shopping is done
Everything's even wrapped
So now I just get to have fun
A weekend of Xbox
Playstation and Wii
So now I might be at work
But soon I'll be free!
And then next week comes
And everyone will be merry
And they'll all call off work
So my tickets won't be scary
Plus a day off on Wednesday
Oh what a delight
So Merry Christmas to all!
Especially SpiceRex

SharePoint 2010: Content Query and Announcement's Body

So recently was asked to make our homepage announcements more informational.  As you can see from below not much in detail.
Currently the items above are pulled from each departments site using Content Query Webpart and SharePoint 2010: Aggregating Announcements (http://cleeit.blogspot.com/2013/08/sharepoint-2010-aggregating-annoucements.html).

So first thing I tried was just to display the Body of the announcement.  Well as you can see below that didn't work.

Content Query does not understand HTML.  So how to escape HTML in Content Query, well off to Google I went. It did not take long to locate Kappa Solutions Technology Blog (at the time rated number 3).

The exact article can be found at:  http://blog.kappasolutions.ca/blog/post/2010/09/12/How-to-Display-HTML-in-Content-Query-Web-Part.aspx

Spiceworks How-To write up: http://community.spiceworks.com/how_to/show/62085-sharepoint-2010-content-query-and-announcement-s-body

As there write up is quite nice I will only link to them for now.

End Results

Monday, December 2, 2013

Microsoft Virtual Academy: PowerShell M04

Today I continue forward on my goal of completing Microsoft's Virtual Academy's PowerShell 3.0 training.
(http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start?o=3276#?fbid=aVs9FfAH2DJ)
(rewritten based on my notes available here:
https://drive.google.com/file/d/0B1fwreWrAZioVFozYmprdHJGT3c/edit?usp=sharing)

Module 4 "Objects for the Admin" consists of 3 video segments totaling ≈ 50 minutes along with a PowerPoint of 13 slides.

Focus on this module is Objects (just as the title states, huh weird).

First off we learn what an object is and how it makes our lives easier in PowerShell.

  • Object
    • has properties
      • things we can view about the object
    • has methods
      • things we can do to the object
Now that we know what an object is how can we see what properties, methods, etc it has.   Well this is where they give us a powerful cmdlet: get-member (gm).  By using the pipeline to send an object through Get-Member PowerShell spits out data providing all the details.  Some key areas to pay attention to are:
  • ObjectType
    • Tells us what type of object we are viewing, import in later modules
  • MemberType
    • Displays all the properties, methods, etc
An interesting segment of the module was importing third party xml file and showing how easily PowerShell can manipulate and pull data from it.
  • Demo of Romeo and Juliet XML play, truly a powerful example of PowerShell
Introduction to filtering and limiting within PowerShell with the use of Select and Where.
  • Select-Object (Select)
    • By piping a cmdlet to Select you can limit what is displayed
      • get-process | Select -Property name, ID
  • Where-Object (where)
    • 2 version
      • Most powerful and versatile uses filterscript {} ({ })
        • assigns current object to variable ($_ or $PSItem)
        • evaluates the code (comparison operators)
          • More details on comparison operators or operators use get-help about_operators
        • acts on results
          • true passing it forward
          • false thrown away
      • Simpler is just the where
        • where property operator value
        • where name -like wmi*
    •  

During their responses to Q&A we learn that for the most part PowerShell v3 is case insensitive when it can, usually third party modules. 


References mentioned in this module:

  • PowerShell.org
    • Forums, FREE eBOOKs, articles, podcasts, script repository
  • Learn Windows PowerShell 3 in a Month of Lunches
    • Don Jones
    • Chapter 9