Just now I received an email from PowerShell MVP Shay Levy stating that in my previous post I’m using somthing that doesn’t exist.
He was totally right.
I’m calling a Test-ItemProperty and indeed, no such cmdlet exists on a normal installation of the Windows operating system.
That’s because it’s part of my personal toolkit… whoops!
So, here’s a small function to test if a property to an item even exists:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
function Test-ItemProperty ( [string] $Path, [string] $Name ) { if ( Test-Path $Path ) { try { $ItemProperty = Get-ItemProperty -Path $Path -Name $Name if ( $ItemProperty -ne $null ) { return $true } else { return $false } } catch { return $false } } else { return $false } } |