http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!2089.entry

A couple things come to mind:

  1. Why aren’t they just referencing the same ParameterAttribute the way C# does?
  2. Specifying System.Management.Automation.ParameterAttribute doesn’t work either. It causes the error message to complain about not being able to find an attribute class that very much does exist.
  3. Are they planning on supporting .NET attributes or maybe even classes in the future? (The PowerShell purist in me says “no no”, but the C# guy in me says “yes yes”!)
  4. Shouldn’t it raise the error at the time the function is defined and not when it is invoked?
function Blah {
   [CmdletBinding()]
   param(
      [System.Management.Automation.ParameterAttribute (Mandatory=$true)]
      [String] $Name
    )
    
    "Hello $Name"
    
}

Blah "Jerry"
Blah "Newman"

Update: I should have mentioned this is specific to PowerShell 2.0 CTP 3 and may not work this way when it is released.

As far as I can tell, this is undocumented. But with a little help from Reflector and Get-Command, I stumbled upon a parameter to the Import-Module command called ArgumentList. It seems this lets you pass parameters to the module in your Import-Module call and they show up in the $Args special variable.

This is pretty useful if I have a module that is otherwise reusable except for some "Josh-specific" stuff that wouldn’t work on someone else’s machine. For example, I have a module that wraps up a bunch of SharePoint web services functionality. But it’s kind of a pain to have to specify the same URL over and over again.

So in my profile.ps1, this is how I am loading the module:

Import-Module Telecommunications
Import-Module BAF
Import-Module SNMP
Import-Module MetaSwitch
Import-Module LERG
Import-Module VMWare

Import-Module SharePointWS -ArgumentList 'http://sharepoint.lsi.local'

And at the top of my SharePointWS.psm1, this is how I am accessing the argument.

if ($Args.Length) {
    $Script:DefaultSharePointUrl = $Args[0]
}

I haven’t really been very good at keeping a blog and pretty much nobody that I’ve invited into my Windows Live network uses the cool new social networking features because they’re all grownups and social networking is for teenagers and nerdy dorks who didn’t have real friends in school. So that’s a long way of saying probably nobody is reading this and if you are, I just pissed you off.

But anyway I’m super pumped because I’m finally all moved into my new house. I think we got a great deal on it. It’s about 2 years old and the previous owners lived here about a year before losing the house to foreclosure. Fortunately they didn’t trash the place because it’s in brand new condition and we got a great deal on it.

While I hate to see anybody lose their house, it was pretty clear to me a few years ago that the prices of homes were way out of control and despite enormous pressure from friends and relatives and a screaming 2 year old, I held my ground and we lived in our little condo in Deptford until I was pretty sure of 2 things:

  1. I was in a stable work environment that didn’t depend on sales of TEO or the next potential consulting gig.
  2. The housing market had bottomed out and I was going to get a really good deal on someone else’s miscalculation.

In fact, I was even offered a job at Microsoft about 2 years ago that I would have loved to accept, but the prices of homes out there were, (and to an extent still are) ridiculous. The house I am living in now for under $300,000 would have easily cost me $700,000 or more out there.

Right now I’m holed up underground in an undisclosed location that I have claimed as my "command center". I will post some more pictures up soon but this basement freakin rocks. There is a divided space that is about the size of my living room and a half which I am reserving for my office. And since Office Depot is closing their doors, I got some nice new furniture and office supplies on the cheap.

Now the trick is staying employed. I’ve been working my ass off at the job, but if money tightens up, none of that matters. So hopefully they find ways to prosper in the shrinking economy and hopefully our fearless leader will find ways to work across the aisle in Washington so that we can pull out of this slump soon.

Here’s a little tip for the security conscious. Over time, you will undoubtedly connect to various networks a couple of times or maybe even just once. But if you’re like me, you probably habitually check (or fail to uncheck) the box that saves the wireless network connection settings.

This can be an accident waiting to happen because let’s say you were living in a hotel for a week like I was while waiting for settlement on a new house. I had connected to an encryption-free wireless network called "lodgenet" which was how this particular hotel’s wireless was set up. Since there was no key, it wouldn’t be difficult for a hacker on a train to set up a fake access point called "lodgenet" and once I’m connected, well then it’s anyone’s guess what would happen next.

But where it’s particularly troublesome is when you connect to an open network called "linksys" or something that an out-of-the-box, unsecured access point defaults to. There’s so many of these that you may find your tablet, iPhone, or what not connecting to all kinds of unscrupulous networks. Hacking issues aside, some people have been *sued* over this crap believe it or not.

Anyway, from time to time, you should go into Network and Sharing Center, click Manage Wireless Networks link on the left, and delete any that you don’t want to automatically connect to.

wireless1  wireless2

I hate to admit it, but the convenience of having PowerShell ISE installed with the core installation of PowerShell 2.0 has been enough to get me to switch from PowerGUI, which is in my opinion a much more full featured free editor/debugger.

One thing that I sorely missed from PowerGUI (which is compounded by the fact that unless you’re on Windows 7, PowerShell ISE doesn’t have a "Recent Files" menu) is the ability to quickly open my profile script without having to browse for it.

Well PowerShell ISE is extensible, so if it lacks a feature, you can just add it in most cases. I’ve uploaded my PowerShell ISE profile which has some useful functions for automating the ISE. But the one in particular that implements the "Open Profile" feature is called….(wait for it)…. Open-Profile!

So you can type that in the immediate window, or use the custom menu item that gets added. It opens the user/global/host/generic/etc profiles if they exist.

function Open-File([String]$Path,[Switch]$Quiet) {

    $AllowedExtensions = @('.ps1','.psm1','.psd1','.ps1xml','.txt','.txt')
    $Extension = [System.IO.Path]::GetExtension($Path)

    try {

        if ( -not ($AllowedExtensions -contains $Extension) ) {
            throw "OpenFile: $Path cannot be opened in PowerShell ISE."
        }
        if ( -not (Test-Path $Path) ) {
            throw "OpenFile: $Path does not exist."
        }

        $Path = (Resolve-Path $Path).ProviderPath
        $PSISE.CurrentOpenedRunspace.OpenedFiles.Add($Path)

    }
    catch {
        if ( -not $Quiet ) { Write-Warning $_ }
    }

}

function Open-Profile {
    Open-File $PROFILE.CurrentUserAllHosts -Quiet
    Open-File $PROFILE.CurrentUserCurrentHost -Quiet
    Open-File $PROFILE.AllUsersAllHosts -Quiet
    Open-File $PROFILE.AllUsersCurrentHost -Quiet
}