Handling square brackets in software name

Topics: Archive - General
Jan 16, 2014 at 3:16 PM
I have a piece of software that uses square brackets in it name. The script fails when running because of these square brackets when looking for installed software. There is a section in the AppDeployToolkitMain.ps1 that replaces special characters, but does not replace [softwarename]. I have tried everything I can find and/or think of. The script either fails or just doesn't run. I need to be able to either ignore or replace the square brackets to get the deployment to work.


Any help removing/ignoring the square brackets would be very helpful. The code for the replace is below. This is my latest attempt at removing the square brackets.
# Replace special characters in product code that interfere with regex match
    $productCode = $productCode -replace "}","" -replace "{","" -replace '\[|]', '_')
    $applications = $name -split (",")
    # Replace special characters in application name that interfere with regex match
    $applications = $applications -replace "\.","" -replace "\*","" -replace "\(","" -replace "\)","" -replace '\[|]', '_') 
    $installedApplication = @()
    Foreach ($regKey in $regKeyApplications ) {
        If (Test-Path $regKey -ErrorAction SilentlyContinue) {
        $regKeyApplication = Get-ChildItem $regKey -ErrorAction SilentlyContinue | ForEach-Object {Get-ItemProperty $_.PsPath}
            Foreach ($regKeyApp in $regKeyApplication) {
                $appDisplayName = $null
                $appDisplayVersion = $null
                $appPublisher = $null
                # Bypass any updates or hotfixes
                If ([RegEx]::Match($regKeyApp.DisplayName, "(?i)kb\d+") -eq $true) { Continue }
                If ($regKeyApp.DisplayName -match "Cumulative Update") { Continue }
                If ($regKeyApp.DisplayName -match "Security Update") { Continue }
                If ($regKeyApp.DisplayName -match "Hotfix") { Continue }
                # Remove any non-standard characters from the name / version which may interfere with logging
                $appDisplayName = [RegEx]::Replace($regKeyApp.DisplayName, "[^\u001F-\u007F]", "")
                $appDisplayVersion = [RegEx]::Replace($regKeyApp.DisplayVersion, "[^\u001F-\u007F]", "")
                $appPublisher = [RegEx]::Replace($regKeyApp.Publisher, "[^\u001F-\u007F]", "")
                If ($ProductCode -ne "") {
                    # Replace special characters in product code that interfere with regex match
                    $regKeyProductCode = $($regKeyApp.PSChildName) -replace "}","" -replace "{","" -replace '\[|]', '_')
Jan 16, 2014 at 9:04 PM
Edited Jan 16, 2014 at 9:05 PM
Forgive me if it is this simple, can you just use the backtick escape char in the software name?

example: [Super Awesome Software]

That should tell powershell not to to attempt to process the brackets as a command.
Edit:  Bah, the forum thinks the backticks are code  How bout this:  `[Super Awesome Software`]
Jan 16, 2014 at 9:10 PM
Possible if the software name only had one set of brackets and the version didn't change. I could comment them out, but I need to comment out all square brackets in a string, or more yet, the software is actually [softwarename] [softwareversion]. The software is a remote control client software that when updated the version changes and would break the script if i hard coded the name. Believe me, i have already complained to the software vendor about the brackets... It has been a pain..
Coordinator
Jan 17, 2014 at 1:33 PM
Fixed in latest release
Jan 17, 2014 at 4:14 PM
Thanks for the update. I downloaded the new version, swapped out the AppDeployToolkitMain.ps1 in my package, tested, with the same results. It throws an error (message below) with just an 'OK' button then exits the script. This issue only happens when looking for installed software. I have other packages using the AppDeployToolkit that is adding and changing registry keys that do not look for installed apps and it works without issue.

Error Message:

"Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard pattern is not valid: Bomgar Jump Client support.learfield.com-1389977896"

The actual display name of the problem software in the registry is: 'Bomgar Jump Client 13.1.1 [support.learfield.com] [1389977896]'

Any help would be greatly appreciated and thank you for your time.
Coordinator
Jan 17, 2014 at 4:43 PM
Can you re-download? I just caught the cause and fixed. Weirdly my initial test worked fine after some fixes - it was only when I tested with the Bomgar Jump Client that I hit the same issue as above. Solved now though!
Marked as answer by rednecknerd on 1/17/2014 at 10:24 AM
Jan 17, 2014 at 5:24 PM
THANK YOU!!!! Just tested and verified it works. You saved the day on this one!!