bugger
Goto Top

Powershell Remote Deinstallation

Hallo,

mich würde interessieren ob es möglich ist, Remote Software zu deinstallieren.
Folgenden Code habe ich:

Function Get-Software { 
    [Cmdletbinding()] 
    Param( 
        [Parameter(Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True,ValueFromRemainingArguments=$False)] 
        [ValidateNotNull()] 
        [String[]]$Computername = @(''),   
        [Switch]$IncludeEmptyDisplaynames 
    ) 
  
     Begin { 
  
         # sub function to convert the registry values to an Object 
         Function Convert-RegistryUninstallSubKeyToObject { 
            param ( 
                [String]$Computername, 
                [microsoft.win32.registrykey]$SubKey 
            ) 
 
            # create New Object with empty Properties 
            $obj = New-Object PSObject | Select-Object ComputerName,DisplayName,DisplayVersion,Publisher,InstallLocation,InstallDate,UninstallString
  
            $obj.ComputerName = $Computername 
            $obj.DisplayName = $SubKey.GetValue('DisplayName')   
            $obj.DisplayVersion = $SubKey.GetValue('DisplayVersion')   
            $obj.Publisher = $SubKey.GetValue('Publisher')   
            $obj.InstallLocation = $SubKey.GetValue('InstallLocation')   
            $obj.InstallDate = $SubKey.GetValue('InstallDate')   
            $obj.UninstallString = $SubKey.GetValue('UninstallString')   
             
            # return Object 
            $obj 
        } 
 
    } # end Begin block        
 
    Process {     
        foreach($pc in $Computername){ 
  
            $UninstallPathes = @("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall","SOFTWARE\\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")   
             
            ForEach($UninstallKey in $UninstallPathes) { 
                #Create an instance of the Registry Object and open the HKLM base key 
                Try { 
                    $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$pc)   
                } Catch { 
                    $_ 
                    Continue 
                } 
  
                #Drill down into the Uninstall key using the OpenSubKey Method 
                $regkey=$reg.OpenSubKey($UninstallKey) 
 
                If(-not $regkey) { 
                    Write-Error "Subkey not found in registry: HKLM:\\$UninstallKey `non Machine: $pc"   
                } 
 
                #Retrieve an array of string that contain all the subkey names 
                $subkeys=$regkey.GetSubKeyNames() 
     
                #Open each Subkey and use GetValue Method to return the required values for each 
                foreach($key in $subkeys){ 
  
                    $thisKey=$UninstallKey+"\\"+$key   
  
                    $thisSubKey=$reg.OpenSubKey($thisKey) 
  
                    # prevent Objects with empty DisplayName 
                    if (-not $thisSubKey.getValue("DisplayName") -and (-not $IncludeEmptyDisplaynames)) { continue }   
  
                    # convert registry values to an Object 
                    Convert-RegistryUninstallSubKeyToObject -Computername $PC -SubKey $thisSubKey 
  
                }  # End ForEach $key 
  
                $reg.Close() 
                  
            } # End ForEach $UninstallKey 
        } # End ForEach $pc 
    } # end Process block 
 
    End { 
     
    } # end End block 
  
} #end Function

Get-Software -Computername $objListbox.SelectedItems | sort Computername,DisplayName | ogv -Passthru |

Was ich mir vorstellen könnte wäre, dass man den UninstallString aus der Function mit einem Create Befehl auf dem Remote PC ausführt. Mit Hilfe vom Passthru aus ogv.
win32_product ist ja böse wie ich gelesen habe.^^

Content-Key: 255374

Url: https://administrator.de/contentid/255374

Printed on: April 19, 2024 at 14:04 o'clock

Member: Bugger
Bugger Nov 25, 2014 at 10:28:49 (UTC)
Goto Top
Keiner eine Idee? face-sad
Member: Bugger
Bugger Feb 12, 2015 at 11:19:29 (UTC)
Goto Top
Die Frage ist übrigens noch aktuell face-wink