<%- | Array $e2epackage | -%> $E2ESOFTWARETOCHECK = '<%= $e2epackage %>' function Remove-StringSpecialCharacter { <# .SYNOPSIS This function will remove the special character from a string. .DESCRIPTION This function will remove the special character from a string. I'm using Unicode Regular Expressions with the following categories \p{L} : any kind of letter from any language. \p{Nd} : a digit zero through nine in any script except ideographic http://www.regular-expressions.info/unicode.html http://unicode.org/reports/tr18/ .PARAMETER String Specifies the String on which the special character will be removed .SpecialCharacterToKeep Specifies the special character to keep in the output .EXAMPLE PS C:\> Remove-StringSpecialCharacter -String "^&*@wow*(&(*&@" wow .EXAMPLE PS C:\> Remove-StringSpecialCharacter -String "wow#@!`~)(\|?/}{-_=+*" wow .EXAMPLE PS C:\> Remove-StringSpecialCharacter -String "wow#@!`~)(\|?/}{-_=+*" -SpecialCharacterToKeep "*","_","-" wow-_* .NOTES Francois-Xavier Cat @lazywinadmin www.lazywinadmin.com github.com/lazywinadmin #> [CmdletBinding()] param ( [Parameter(ValueFromPipeline)] [ValidateNotNullOrEmpty()] [Alias('Text')] [System.String[]]$String, [Alias("Keep")] #[ValidateNotNullOrEmpty()] [String[]]$SpecialCharacterToKeep ) PROCESS { IF ($PSBoundParameters["SpecialCharacterToKeep"]) { $Regex = "[^\p{L}\p{Nd}" Foreach ($Character in $SpecialCharacterToKeep) { IF ($Character -eq "-"){ $Regex +="-" } else { $Regex += [Regex]::Escape($Character) } #$Regex += "/$character" } $Regex += "]+" } #IF($PSBoundParameters["SpecialCharacterToKeep"]) ELSE { $Regex = "[^\p{L}\p{Nd}]+" } FOREACH ($Str in $string) { Write-Verbose -Message "Original String: $Str" $Str -replace $regex, "" } } #PROCESS } $SOFTWAREFILE = "C:\currentsoftware.txt" #$SOFTWARETOCHECK = @("notepadplusplus", "microsoft-edge","webex","chrome","nodesare") $E2ESOFTWARETOCHECKLENGTH = $E2ESOFTWARETOCHECK.Length if (!(Test-Path $SOFTWAREFILE)) {    New-Item -path $SOFTWAREFILE -type "file" -Force    Write-Host "Created new file and text content added" } $INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName $INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName $INSTALLED | ?{ $_.DisplayName -ne $null } | sort-object -Property DisplayName -Unique | Format-Table | Out-File -FilePath $SOFTWAREFILE (gc $SOFTWAREFILE) | Foreach {$_.TrimEnd()} | where {$_ -ne ""} | Set-Content $SOFTWAREFILE [string[]]$arrayFromFile = Get-Content -Path $SOFTWAREFILE $arraylength = $arrayFromFile.Length $E2ESOFTWARETOCHECKNEW = Remove-StringSpecialCharacter -String $E2ESOFTWARETOCHECK $arrayFromFileNEW = Remove-StringSpecialCharacter -String $arrayFromFile $substr = $E2ESOFTWARETOCHECKNEW.Substring(0,5) For ($j=0; $j -lt $E2ESOFTWARETOCHECKLENGTH; $j++) { For ($i=2; $i -lt $arraylength; $i++) { if ( $arrayFromFileNEW[$i] -match $E2ESOFTWARETOCHECKNEW[$j] -or $arrayFromFileNEW[$i].ToLower().Contains($substr[$j]) ) { choco upgrade $E2ESOFTWARETOCHECK[$j] Break } } }