Monthly Archive

Categories

Monthly Archives: July 2009

MDT 2010 supports PowerShell

MDT -  Microsoft Deployment Toolkit (was known as BDD in a previous life)  now supports PowerShell with a snapin to give a provider and some cmdlets.  See http://blogs.technet.com/mniehaus/archive/2009/07/10/mdt-2010-new-feature-16-powershell-support.aspx

Technorati Tags: PowerShell,MDT

Maths Functions

I’ve needed to access the maths functions in .NET for a few things recently and finally decided to create functions for the ones I use all the time.  I’ve started with 3 functions and put them into a module. The good thing about this is that I can easily load them dynamically and any other modules I create can load this module.

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
#Requires -version 2.0
function pi {
    [System.Math]::PI
}
function power {
    param ([double]$a, [double]$b)
    [System.Math]::Pow($a, $b)
}
function sqrt {
    param ([double]$a)
    [System.Math]::Sqrt($a)
}
function pi {
    [System.Math]::PI
}

 

Three functions defined so far. 

pi returns the value of PI – 3.142…..

power raises a number to a particular power so

$x = power 3 3

is equivalent to 3*3*3

sqrt returns the square root of the number

if you want other roots use

power 1000 (1/3) to get the cube root – replace 3 by whatever root is required

I’ll add a few more tomorrow.

Technorati Tags: PowerShell,Maths

PowerShell Editing

I have been a fan of the PowerGUI editor since it was first in beta but one thing has been consistently annoying.  I don’t like the way is sets itself as the default editor for PowerShell files and blocks changes to this unless you go into the registry and kill the keys it has set.

Bad PowerGUI!

Let me decide what I want to use to edit a particular file.  There are times when I want or need to use ISE. Don’t get in my way.

Technorati Tags: PowerShell,PowerGUI editor

PowerShell in Practice – Chapter 15

The last chapter – Chapter 15 - has been delivered for first pass editing. This is an extra chapter we decided to add to round off a few topics we thought should be included. Hopefully it will available on MEAP fairly soon.

Two recommendations

I took delivery of a copy of the Hyper-V Resource Kit today.  Only had chance to flick through it but Chapter 16 jumped out at me – Hyper-V Management using Windows PowerShell – unless my powers of deduction are way off this chapter was written by James O’Neill who also wrote the Hyper-V management library that is featured in the chapter – the code is available on codeplex.  I’ve finally had chance to start using it and its turning out to be as good as I expected and knowing James I expected a lot – nice one James.

The book was delivered by Computer Manuals - http://www.compman.co.uk/

Ordered it late yesterday afternoon and it arrives today while I was work.  That’s service. 

July User group meeting

This months meeting will be virtual.  I will arrange another virtual meeting for late August. 

We should have a physical meeting in September


When: Thursday, Jul 23, 2009 7:00 PM (BST)


Where: Virtual

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

Subject is PowerShell output. What we see. What we get. How we can change it. methods of output

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: 94F2K5
    Entry Code: q.bhRK7Hs
    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.

Amazon

My book has appeared on Amazon’s listings

http://www.amazon.co.uk/Powershell-Practice-Richard-Siddaway/dp/1935182005/ref=sr_1_1?ie=UTF8&s=books&qid=1246906667&sr=1-1

http://www.amazon.com/Powershell-Practice-Richard-Siddaway/dp/1935182005/ref=sr_1_1?ie=UTF8&s=books&qid=1246906789&sr=1-1

The dates are slightly optimistic   🙂

Thats nice.  Just need to finish the last chapter and it enters the final phase

Technorati Tags: PowerShell,Books

Playing with dates

I happened to notice that Sundays date was 5 July 2009.  Not particular astute you may think but I noticed it because I’d written it as 5/7/9.  English date format puts the day then the month so this may not make sense in other formats.

The fact that there was a difference to two between the day and the month and the same between the month and the year intrigued me.  It doesn’t take much. So I decided to look at other dates that follow that pattern

001
002
003
004
for ($i=3; $i -le 12; $i++){
    $date = Get-Date -Month $i -Day $($i -2) -Year $(2000 + $i +2)
    "{0} {1}" -f $date.DayOfWeek, $date.ToShortDateString()   
}

 

It doesn’t need much to do this.  A for loop – notice we start at 3 so we don’t get into negative days. Time travel by PowerShell now there’s a thought

Get-Date | Set-Now –Era Jurassic

gets us back to the dinosaurs.  OK I’ll stop.

We can use Get-Date and give it a month, day and year to create the date.  Note that I add 2000 to get the current sequence of dates. This sequence will happen every century.  One thing I noticed was that Get-Date takes the year you give it literally.  It doesn’t make any allowance for the century if you don’t supply the full year.  Compare

PS> Get-Date -Day 1 -Month 1 -Year 9

01 January 0009 19:46:48

PS> [datetime]"1/1/9"

01 January 2009 00:00:00

Finally I use a formatted string to display the date (in short form) and the day of the week.  The day of week doesn’t appear to add any more information but I was curious.

Technorati Tags: PowerShell,Dates

DHCP cmdlets

Documentation on TechNet states that there are cmdlets for managing DHCP servers on Windows 2008 R2.  This appears to be an error as there is no sign of them after installing DHCP.

Technorati Tags: Windows 2008 R2

HP G60

I am currently using a HP G60 laptop.  Runs Windows 7 very well. I created a dual boot environment so I could install Windows 2008 R2 and to my pleasant surprise found Hyper-V runs on it.  Need to enable virtualisation in the BIOS but apart from that slight hiccup it installs and works very well.  Once I get the RTM version it will be time to finally abandon Virtual PC.

Also gives me a chance to play with James’ Hyper-V library.

Technorati Tags: Windows 2008 R2