07 Jan 2015 @ 2:15 PM 

This has been done a lot of times, by multiple people.
I thought it was about time to share my function with you which allows you to list installed applications / programs on remote (Windows) devices.

function Get-RemoteApplication {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param(
        [Parameter(
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            Position=1
        )]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )
    begin {
        $RegistryPath = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\',
                            'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'
    } process {
        foreach ($Computer in $ComputerName) {
            $Registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
            foreach ($RegPath in $RegistryPath) {
                ($Registry.OpenSubKey($RegPath)) | foreach {
                    $_.GetSubKeyNames() | ForEach-Object {
                        $ApplicationName = ($Registry.OpenSubKey("$RegPath$_")).GetValue('DisplayName')
                        if ([bool]$ApplicationName) {
                            New-Object -TypeName PSCustomObject -Property @{
                                'ComputerName' = $Computer
                                'Application' = $ApplicationName
                            }
                        }
                    }
                }
            }
        }
    }
}
Posted By: Jeff Wouters
Last Edit: 07 Jan 2015 @ 02:15 PM

EmailPermalinkComments (0)
Tags

 19 Dec 2014 @ 7:30 AM 

Checking if a variable has a value is something I do very often in my scripts.
Most of the times, I do this by checking if the variable equals to $null.
However, there is a more performance friendly way to do this…

First, let’s create a few variables, which have the four most common types:

1

Next, let’s verify the types, just to show you that check it in the way I will show you, works for most (if not all) variable types:

2

Now to actually check if the variables have values:

3

…and to show you it correctly tells me if the parameter does exist, yet has no value in it:

4

Posted By: Jeff Wouters
Last Edit: 19 Dec 2014 @ 07:30 AM

EmailPermalinkComments (0)
Tags
Categories: DuPSUG, PowerShell





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

About



    No Child Pages.

Contact



    No Child Pages.

Speaking



    No Child Pages.

Health Check



    No Child Pages.