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-ID: 255374

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

Ausgedruckt am: 04.12.2024 um 08:12 Uhr

Bugger
Bugger 25.11.2014 um 11:28:49 Uhr
Goto Top
Keiner eine Idee? face-sad
Bugger
Bugger 12.02.2015 um 12:19:29 Uhr
Goto Top
Die Frage ist übrigens noch aktuell face-wink