Monthly Archives: June 2012

OMI

You may have noticed that I mention WMI from time to time Smile

 

Up to now WMI has been a Windows technology. Powerful but limited to Windows.  WMI has taken a giant step into the big bad world with the creation of OMI – Open Management Infrastructure thats WMI for non-Windows systems

Details are here

http://blogs.technet.com/b/windowsserver/archive/2012/06/28/open-management-infrastructure.aspx

and

https://collaboration.opengroup.org/omi/

Expect more on this in the months to come

Free books 27 June 2012

Want some free ebooks?

Check out

http://social.technet.microsoft.com/wiki/contents/articles/11608.e-book-gallery-for-microsoft-technologies-en-us.aspx#Configure%20Kerberos%20Authentication%20for%20SharePoint%202010%20Products

Write-Host Wrong!

Many scripting languages require you explicitly write out to screen – VBScript was an example.

This leads to PowerShell that looks like this

Get-Service |
foreach {
  Write-Host $_.Name, $_.Status
}

This is bad on so many levels.

Firstly you are doing too much work. Secondly you are emitting text not objects. Thirdly you are doing too much work.

Get-Service |
Format-Table Name, Status –AutoSize

gives a much better result and if you are working at the prompt can be aliased to

gsv | ft Name, Status –a

The last act of the pipeline is to pass the data to Out-Default which performs the screen writing.  Write-Host also passes data to Out-Default which effectively terminates the pipeline.

You should always format the data for display as far into the processing as you possibly can. Once you have called a format cmdlet or Write-Host you have terminated the pipeline.

The best you will get is the text representation that would have been displayed on screen. The worst is garbage output.

So if you want to create a HTML report then

Get-Service |
Select Name, Status |
ConvertTo-Html |
Out-File test.htm

Invoke-Item test.htm

Stick with objects and let the pipeline do the work

How do I do X in PowerShell?

Many forum questions revolve around that question.  In some cases the answer is that its not possible.

It might not be possible because PowerShell itself can’t do something BUT it is much more likely that there just isn’t away to do that particular action programmatically (through a script).

Its always a good idea to work out how you are going to do something before you try to figure out how you will get PowerShell to do it for you

Reminder–UK PowerShell Group–July 2012 meeting


When: Wednesday, Jul 4, 2012 8:30 PM (BST)


Where: Virtual

*~*~*~*~*~*~*~*~*~*


Jonathan Medd will be talking about using PowerShell to administer a XenDesktop environment

Notes



Richard Siddaway has invited you to attend an online meeting using Live Meeting.
Join the meeting.
Audio Information
Computer Audio
To use computer audio, you need speakers and microphone, or a headset.
First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Troubleshooting
Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:
    https://www.livemeeting.com/cc/usergroups/join
  2. Copy and paste the required information:
    Meeting ID: R2TT4R
    Entry Code: Jc-'8JM;W
    Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Notice
Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.

WMI property names

A question brought it home to me that WMI property names don’t always mean what you might think they mean – this is also true of other objects but I tripped over this one with WMI so we’ll stick with that.

PS> Get-CimInstance -ClassName Win32_Desktop -Filter "Name LIKE '%Richard'" |
>> Format-List ScreenSaver*
>>


ScreenSaverActive     : True
ScreenSaverExecutable : C:\Windows\system32\PhotoScreensaver.scr
ScreenSaverSecure     : True
ScreenSaverTimeout    : 600

 

The ScreenSaverActive property doesn’t mean that the screen saver is currently active – it means that one has been set!   This is doubly confusing because the documentation states

ScreenSaverActive
Data type: boolean
Access type: Read-only

Screen saver is active.

Which would lead you to think that is was actually running!

The ScreenSaverSecure means that a password has been set to unlock the system once the screen saver kicks in & ScreenSaverTimeout is the idle time in seconds before the screen saver kicks in. The executable is the screen saver that will be used.

If you want to get the information with the WMI cmdlets use

PS> Get-WmiObject Win32_Desktop -Filter "Name LIKE '%Richard'" |
>> Format-List ScreenSaver*
>>


ScreenSaverActive     : True
ScreenSaverExecutable : C:\Windows\system32\PhotoScreensaver.scr
ScreenSaverSecure     : True
ScreenSaverTimeout    : 600

Pipeline input

A question on the forum asked about creating a function that accepts pipeline input OR has a path parameter.  Means it can be used like this

myfunction -Path C:\scripts\Test\proc.csv

or

(Get-Content C:\scripts\Test\files.txt) | myfunction

First create a csv file

Get-Process | Export-Csv proc.csv –NoTypeInformation

and test its contents

Import-Csv proc.csv

The full path to the csv file is:-  C:\scripts\Test\proc.csv

The function is like this

function myfunction{             
[CmdletBinding()]             
param (             
[parameter(ValueFromPipeline=$true,             
   ValueFromPipelineByPropertyName=$true)]            
   [string]$Path            
)             
PROCESS{            
 if (-not (Test-Path -Path $path)){            
   Throw "Path NOT found $path"            
 }            
            
 Import-Csv -Path $path            
            
}#process             
            
}


Use [CmdletBinding()] to get the debug and verbose parameters



Use ValueFromPipeline and ValueFromPipelineByPropertyName attributes [parameter()]



This covers generic input and if we have a csv with path as a column.



if you are accepting pipeline input you need to use a PROCESS block



Then the path is tested and rejected if not valid. Finally import-csv is used to read the file

UK PowerShell Group–July 2012


When: Wednesday, Jul 4, 2012 8:30 PM (BST)


Where: Virtual

*~*~*~*~*~*~*~*~*~*


Jonathan Medd will be talking about using PowerShell to administer a XenDesktop environment

Notes



Richard Siddaway has invited you to attend an online meeting using Live Meeting.
Join the meeting.
Audio Information
Computer Audio
To use computer audio, you need speakers and microphone, or a headset.
First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Troubleshooting
Unable to join the meeting? Follow these steps:

  1. Copy this address and paste it into your web browser:
    https://www.livemeeting.com/cc/usergroups/join
  2. Copy and paste the required information:
    Meeting ID: R2TT4R
    Entry Code: Jc-'8JM;W
    Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Notice
Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.

Colossus

I went to Bletchley Park today - http://www.bletchleypark.org.uk/

One of the exhibits there is the Colossus machine – regarded as the World’s first computer. Imagine a machine that has 2 rows of electronics each 5 racks wide by 1 rack high.  All of this delivers the computing power of a pentium 2 chip and consumes 7.5KW of electricity.

The machine uses 1500 valves (some still from the original 1943 machine) and gives off a tremendous amount of heat

If you are in the area I recommend a visit – its quite staggering to compare where we are today with this first machine

Rant: Wireless connectivity at airports

I’ve been on two international trips this year – one to San Diego & one to Vienna flying out of London Heathrow and London Gatwick respectively.

Both San Diego and Vienna supply free wireless connectivity that works.

Heathrow and Gatwick don’t – isn’t it about time they entered at least the 20th century