none
Ausgabe als Parameter verwenden RRS feed

  • Frage

  • Guten Tag,

    ich versuche gerade die Ausgabe eines Befehls als Parameter / Wert in einen Befehl einzufügen. Leider funktioniert es nicht richtig. Im folgenden möchte ich überprüfen ob "Adobe Reader" installiert ist und wenn ja soll er die "IdentifyingNumber" in die Variable $adobeid stecken.

    Ein Echo gibt die ID aus, bis hierhin funktioniert es also. Jetzt möchte ich diese "IdentifyingNumber" an "msiexec.exe" übergeben zum deinstallieren der Software.

    Msiexec meldet bloss ein Hilfefenster mit möglichen Parametern die ich eingeben kann.

    Wie also füge ich nur die "IdentifyingNumber" ein ? Damit Msiexec ein Uninstall durchführt ?

    Hier mein Code:

    # Adobe Reader Suchen und löschen
    echo "... Adobe Reader Versionen werden gesucht ...";
    $adobeid = Get-WmiObject -Class Win32_Product | where{$_-match 'adobe reader'} | Select-Object IdentifyingNumber
    
    if ($adobeid)
        {
        echo "... Adobe Reader alt wird entfernt ..."
        msiexec.exe /x $adobeid /qn
        
        echo "... Adobe wurde entfernt ..."
        }
        else
        {
        echo "Ist False";
        }

    Ich bitte um schnelle Hilfe.

    Gruß

    Rafael

    Dienstag, 3. Dezember 2013 06:01

Antworten

  • Es wird nicht empfohlen Win32_Product für so etwas zu benutzen.
    1. ist Win32_Product sehr langsam da es nicht gut filtert
    2. Win32_Product verursacht bei jedem Aufruf einen Software Konsistenz-Check dieser macht Win32_Product ebenfalls sehr langsam und es kann Software geben die sich dann wieder neu Installieren / reparieren will!

    Siehe hier: http://blogs.technet.com/b/askds/archive/2012/04/19/how-to-not-use-win32-product-in-group-policy-filtering.aspx
    http://gregramsey.net/2012/02/20/win32_product-is-evil/

    Die Alternative Lösung ist die beiden folgenden Registry Schlüssel auszulesen
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    HKLM\SOFTWARE\Wow6432node\Microsoft\Windows\CurrentVersion\Uninstall

    In diesem Registry Schlüsseln steckt (fast) immer der „Uninstallstring“ mit dem die Software deinstalliert werden sollte.
    Dieser sollte auch genutzt werden! Da alles andere unerwünschte Reste hinterlassen kann!

    Function Get-InstalledSoftware {
    # Function to read the installed Software from a (remote) computer
    # Parameter Computername if you leave it empty the local Computer is processed
    # Parameter IncludeEmptyDisplaynames returns even Software Objects with empty Displaynames
    # Default is to NOT return Software Objects with empty Displaynames
    # 03.December.2013 Peter Kriegel
    
        
        Param(
            [String[]]$Computername = @(''),
            [Switch]$IncludeEmptyDisplaynames
        )
            
        
        foreach($pc in $Computername){
    
            $UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" 
    
            #Create an instance of the Registry Object and open the HKLM base key
            $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$pc) 
    
            #Drill down into the Uninstall key using the OpenSubKey Method
            $regkey=$reg.OpenSubKey($UninstallKey) 
    
            #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 }
    
                # create New Object with empty Properties
                $obj = New-Object PSObject | Select-Object ComputerName,AuthorizedCDFPrefix,Comments,Contact,DisplayVersion,HelpLink,HelpTelephone,InstallDate,InstallLocation,InstallSource,ModifyPath,Publisher,Readme,Size,EstimatedSize,UninstallString,URLInfoAbout,URLUpdateInfo,VersionMajor,VersionMinor,WindowsInstaller,Version,Language,DisplayName
    
                $obj.ComputerName = $pc
                $obj.AuthorizedCDFPrefix = $thisSubKey.GetValue('AuthorizedCDFPrefix')
                $obj.Comments = $thisSubKey.GetValue('Comments')
                $obj.Contact = $thisSubKey.GetValue('Contact')
                $obj.DisplayVersion = $thisSubKey.GetValue('DisplayVersion')
                $obj.HelpLink = $thisSubKey.GetValue('HelpLink')
                $obj.HelpTelephone = $thisSubKey.GetValue('HelpTelephone')
                $obj.InstallDate = $thisSubKey.GetValue('InstallDate')
                $obj.InstallLocation = $thisSubKey.GetValue('InstallLocation')
                $obj.InstallSource = $thisSubKey.GetValue('InstallSource')
                $obj.ModifyPath = $thisSubKey.GetValue('ModifyPath')
                $obj.Publisher = $thisSubKey.GetValue('Publisher')
                $obj.Readme = $thisSubKey.GetValue('Readme')
                $obj.Size = $thisSubKey.GetValue('Size')
                $obj.EstimatedSize = $thisSubKey.GetValue('EstimatedSize')
                $obj.UninstallString = $thisSubKey.GetValue('UninstallString')
                $obj.URLInfoAbout = $thisSubKey.GetValue('URLInfoAbout')
                $obj.URLUpdateInfo = $thisSubKey.GetValue('URLUpdateInfo')
                $obj.VersionMajor = $thisSubKey.GetValue('VersionMajor')
                $obj.VersionMinor = $thisSubKey.GetValue('VersionMinor')
                $obj.WindowsInstaller = $thisSubKey.GetValue('WindowsInstaller')
                $obj.Version = $thisSubKey.GetValue('Version')
                $obj.Language = $thisSubKey.GetValue('Language')
                $obj.DisplayName = $thisSubKey.GetValue('DisplayName')
                
                # return Object
                $obj
    
            }  # End ForEach $key
    
            $reg.Close()
    
            $UninstallKey= "SOFTWARE\\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
    
            #Create an instance of the Registry Object and open the HKLM base key
            $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$pc) 
    
            #Drill down into the Uninstall key using the OpenSubKey Method
            $regkey=$reg.OpenSubKey($UninstallKey) 
    
            #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 }
    
                # create New Object with empty Properties
                $obj = New-Object PSObject | Select-Object ComputerName,AuthorizedCDFPrefix,Comments,Contact,DisplayVersion,HelpLink,HelpTelephone,InstallDate,InstallLocation,InstallSource,ModifyPath,Publisher,Readme,Size,EstimatedSize,UninstallString,URLInfoAbout,URLUpdateInfo,VersionMajor,VersionMinor,WindowsInstaller,Version,Language,DisplayName
    
                $obj.ComputerName = $pc
                $obj.AuthorizedCDFPrefix = $thisSubKey.GetValue('AuthorizedCDFPrefix')
                $obj.Comments = $thisSubKey.GetValue('Comments')
                $obj.Contact = $thisSubKey.GetValue('Contact')
                $obj.DisplayVersion = $thisSubKey.GetValue('DisplayVersion')
                $obj.HelpLink = $thisSubKey.GetValue('HelpLink')
                $obj.HelpTelephone = $thisSubKey.GetValue('HelpTelephone')
                $obj.InstallDate = $thisSubKey.GetValue('InstallDate')
                $obj.InstallLocation = $thisSubKey.GetValue('InstallLocation')
                $obj.InstallSource = $thisSubKey.GetValue('InstallSource')
                $obj.ModifyPath = $thisSubKey.GetValue('ModifyPath')
                $obj.Publisher = $thisSubKey.GetValue('Publisher')
                $obj.Readme = $thisSubKey.GetValue('Readme')
                $obj.Size = $thisSubKey.GetValue('Size')
                $obj.EstimatedSize = $thisSubKey.GetValue('EstimatedSize')
                $obj.UninstallString = $thisSubKey.GetValue('UninstallString')
                $obj.URLInfoAbout = $thisSubKey.GetValue('URLInfoAbout')
                $obj.URLUpdateInfo = $thisSubKey.GetValue('URLUpdateInfo')
                $obj.VersionMajor = $thisSubKey.GetValue('VersionMajor')
                $obj.VersionMinor = $thisSubKey.GetValue('VersionMinor')
                $obj.WindowsInstaller = $thisSubKey.GetValue('WindowsInstaller')
                $obj.Version = $thisSubKey.GetValue('Version')
                $obj.Language = $thisSubKey.GetValue('Language')
                $obj.DisplayName = $thisSubKey.GetValue('DisplayName')
                
                # return Object
                $obj
    
            }  # End ForEach $key
    
             $reg.Close()
    
    
        } # End ForEach $pc
    
    }
    
    Get-InstalledSoftware | Where-Object {$_.DisplayName -match 'adobe reader'} | Select-Object UninstallString


    PowerShell Artikel, Buchtipps und kostenlose PowerShell Tutorials + E-Books
    auf der deutschsprachigen PowerShell Community

    Mein 21 Teiliger PowerShell Video Grundlehrgang
    Deutsche PowerShell Videos auf Youtube
    Folge mir auf:
    Twitter | Facebook | Google+

    Dienstag, 3. Dezember 2013 08:28

Alle Antworten

  • Hallo Rafael,

    hilft dir das ev. weiter?

    http://support.microsoft.com/kb/296067/de

    http://stackoverflow.com/questions/4124409/run-msiexec-from-powershell-and-get-return-code

    Und: Hat der Benutzer genügend Rechte, das Paket zu entfernen?

    Grüsse

    Florian


    Schaue auf niemanden herab, es sei denn, du willst ihm aufhelfen...

    Dienstag, 3. Dezember 2013 08:04
  • Es wird nicht empfohlen Win32_Product für so etwas zu benutzen.
    1. ist Win32_Product sehr langsam da es nicht gut filtert
    2. Win32_Product verursacht bei jedem Aufruf einen Software Konsistenz-Check dieser macht Win32_Product ebenfalls sehr langsam und es kann Software geben die sich dann wieder neu Installieren / reparieren will!

    Siehe hier: http://blogs.technet.com/b/askds/archive/2012/04/19/how-to-not-use-win32-product-in-group-policy-filtering.aspx
    http://gregramsey.net/2012/02/20/win32_product-is-evil/

    Die Alternative Lösung ist die beiden folgenden Registry Schlüssel auszulesen
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    HKLM\SOFTWARE\Wow6432node\Microsoft\Windows\CurrentVersion\Uninstall

    In diesem Registry Schlüsseln steckt (fast) immer der „Uninstallstring“ mit dem die Software deinstalliert werden sollte.
    Dieser sollte auch genutzt werden! Da alles andere unerwünschte Reste hinterlassen kann!

    Function Get-InstalledSoftware {
    # Function to read the installed Software from a (remote) computer
    # Parameter Computername if you leave it empty the local Computer is processed
    # Parameter IncludeEmptyDisplaynames returns even Software Objects with empty Displaynames
    # Default is to NOT return Software Objects with empty Displaynames
    # 03.December.2013 Peter Kriegel
    
        
        Param(
            [String[]]$Computername = @(''),
            [Switch]$IncludeEmptyDisplaynames
        )
            
        
        foreach($pc in $Computername){
    
            $UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" 
    
            #Create an instance of the Registry Object and open the HKLM base key
            $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$pc) 
    
            #Drill down into the Uninstall key using the OpenSubKey Method
            $regkey=$reg.OpenSubKey($UninstallKey) 
    
            #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 }
    
                # create New Object with empty Properties
                $obj = New-Object PSObject | Select-Object ComputerName,AuthorizedCDFPrefix,Comments,Contact,DisplayVersion,HelpLink,HelpTelephone,InstallDate,InstallLocation,InstallSource,ModifyPath,Publisher,Readme,Size,EstimatedSize,UninstallString,URLInfoAbout,URLUpdateInfo,VersionMajor,VersionMinor,WindowsInstaller,Version,Language,DisplayName
    
                $obj.ComputerName = $pc
                $obj.AuthorizedCDFPrefix = $thisSubKey.GetValue('AuthorizedCDFPrefix')
                $obj.Comments = $thisSubKey.GetValue('Comments')
                $obj.Contact = $thisSubKey.GetValue('Contact')
                $obj.DisplayVersion = $thisSubKey.GetValue('DisplayVersion')
                $obj.HelpLink = $thisSubKey.GetValue('HelpLink')
                $obj.HelpTelephone = $thisSubKey.GetValue('HelpTelephone')
                $obj.InstallDate = $thisSubKey.GetValue('InstallDate')
                $obj.InstallLocation = $thisSubKey.GetValue('InstallLocation')
                $obj.InstallSource = $thisSubKey.GetValue('InstallSource')
                $obj.ModifyPath = $thisSubKey.GetValue('ModifyPath')
                $obj.Publisher = $thisSubKey.GetValue('Publisher')
                $obj.Readme = $thisSubKey.GetValue('Readme')
                $obj.Size = $thisSubKey.GetValue('Size')
                $obj.EstimatedSize = $thisSubKey.GetValue('EstimatedSize')
                $obj.UninstallString = $thisSubKey.GetValue('UninstallString')
                $obj.URLInfoAbout = $thisSubKey.GetValue('URLInfoAbout')
                $obj.URLUpdateInfo = $thisSubKey.GetValue('URLUpdateInfo')
                $obj.VersionMajor = $thisSubKey.GetValue('VersionMajor')
                $obj.VersionMinor = $thisSubKey.GetValue('VersionMinor')
                $obj.WindowsInstaller = $thisSubKey.GetValue('WindowsInstaller')
                $obj.Version = $thisSubKey.GetValue('Version')
                $obj.Language = $thisSubKey.GetValue('Language')
                $obj.DisplayName = $thisSubKey.GetValue('DisplayName')
                
                # return Object
                $obj
    
            }  # End ForEach $key
    
            $reg.Close()
    
            $UninstallKey= "SOFTWARE\\Wow6432node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
    
            #Create an instance of the Registry Object and open the HKLM base key
            $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$pc) 
    
            #Drill down into the Uninstall key using the OpenSubKey Method
            $regkey=$reg.OpenSubKey($UninstallKey) 
    
            #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 }
    
                # create New Object with empty Properties
                $obj = New-Object PSObject | Select-Object ComputerName,AuthorizedCDFPrefix,Comments,Contact,DisplayVersion,HelpLink,HelpTelephone,InstallDate,InstallLocation,InstallSource,ModifyPath,Publisher,Readme,Size,EstimatedSize,UninstallString,URLInfoAbout,URLUpdateInfo,VersionMajor,VersionMinor,WindowsInstaller,Version,Language,DisplayName
    
                $obj.ComputerName = $pc
                $obj.AuthorizedCDFPrefix = $thisSubKey.GetValue('AuthorizedCDFPrefix')
                $obj.Comments = $thisSubKey.GetValue('Comments')
                $obj.Contact = $thisSubKey.GetValue('Contact')
                $obj.DisplayVersion = $thisSubKey.GetValue('DisplayVersion')
                $obj.HelpLink = $thisSubKey.GetValue('HelpLink')
                $obj.HelpTelephone = $thisSubKey.GetValue('HelpTelephone')
                $obj.InstallDate = $thisSubKey.GetValue('InstallDate')
                $obj.InstallLocation = $thisSubKey.GetValue('InstallLocation')
                $obj.InstallSource = $thisSubKey.GetValue('InstallSource')
                $obj.ModifyPath = $thisSubKey.GetValue('ModifyPath')
                $obj.Publisher = $thisSubKey.GetValue('Publisher')
                $obj.Readme = $thisSubKey.GetValue('Readme')
                $obj.Size = $thisSubKey.GetValue('Size')
                $obj.EstimatedSize = $thisSubKey.GetValue('EstimatedSize')
                $obj.UninstallString = $thisSubKey.GetValue('UninstallString')
                $obj.URLInfoAbout = $thisSubKey.GetValue('URLInfoAbout')
                $obj.URLUpdateInfo = $thisSubKey.GetValue('URLUpdateInfo')
                $obj.VersionMajor = $thisSubKey.GetValue('VersionMajor')
                $obj.VersionMinor = $thisSubKey.GetValue('VersionMinor')
                $obj.WindowsInstaller = $thisSubKey.GetValue('WindowsInstaller')
                $obj.Version = $thisSubKey.GetValue('Version')
                $obj.Language = $thisSubKey.GetValue('Language')
                $obj.DisplayName = $thisSubKey.GetValue('DisplayName')
                
                # return Object
                $obj
    
            }  # End ForEach $key
    
             $reg.Close()
    
    
        } # End ForEach $pc
    
    }
    
    Get-InstalledSoftware | Where-Object {$_.DisplayName -match 'adobe reader'} | Select-Object UninstallString


    PowerShell Artikel, Buchtipps und kostenlose PowerShell Tutorials + E-Books
    auf der deutschsprachigen PowerShell Community

    Mein 21 Teiliger PowerShell Video Grundlehrgang
    Deutsche PowerShell Videos auf Youtube
    Folge mir auf:
    Twitter | Facebook | Google+

    Dienstag, 3. Dezember 2013 08:28
  • Donnerstag, 5. Dezember 2013 09:10
  • Hi,

    sry, ich war etwas ausgelastet. Wie führe ich den Uninstallstring jetzt aus ? Er wird mir nur ausgegeben !

    Sry ich bin da sehr neu.

    Gruß

    Rafael

    Samstag, 14. Dezember 2013 23:30