09 May 2013 @ 11:29 AM 

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:

function Test-ItemProperty ( [string] $Path, [string] $Name )
{
  if ( Test-Path $Path )
  {
    try
    {
      $ItemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
      if ( $ItemProperty -ne $null ) { return $true }
      else { return $false }
    }
    catch
    {
      return $false
    }
  }
  else { return $false }
}

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 09 May 2013 @ 11:33 AM

EmailPermalinkComments (2)
Tags
Categories: DuPSUG, PowerShell

 09 May 2013 @ 10:09 AM 

This morning I was contacted by an IT Pro asking me if I could write some PowerShell code to enable and disable MSI logging.
He both wanted to use it from a command line and needed it to be part of a big troubleshooting script he’s working on; so reusable code.

First up is a function to enable the MSI logging:

function Enable-MSILogging
{
  if((Test-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Installer" -Name "Logging" ) -eq $False)
  {
    New-Item -Path "HKLM:\Software\Policies\Microsoft\Windows\Installer" -Force
  }
  Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Installer" -Name "Logging" -Value "voicewarmupx" -Force
}

Next is a function to disable the MSI logging:

function Disable-MSILogging
{
  if(Test-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Installer" -Name "Logging")
  {
    Remove-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Installer" -Name "Logging" -Force
  }
}

As you can see I’m simply using the registry to enable/disable it.
I’m currently writing some other functions that I’ll post in the near future.

Update: Shay Levy contacted me stating that I’m using Test-ItemProperty and that doesn’t exist. He’s correct since it’s part of my personal toolkit. So I’ve decided to share it with you here.

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 09 May 2013 @ 11:33 AM

EmailPermalinkComments (0)
Tags





 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 248
  • Comments » 429
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.