Это должно сделать это.
# Check to see if AWP is actually installed
$awpPath = "C:\Program Files\Middleware\Card"
$aWPExists = Test-Path $awpPath
$toAppend = "
library=C:\Program Files\Middleware\middleware.dll
name=PKCS 11 Middleware
"
# If AWP Exists copy the pkcs11.txt file to all Firefox Profiles found.
$pKCSFiles = Get-ChildItem -Path 'C:\Users\*\AppData\Roaming\Mozilla\Firefox\Profiles\*\pkcs11.txt'
If ($aWPExists -eq $True) {
Write-Log "AWP Exists and module wasn't found in the pkcs11.txt file. Copying pkcs11.txt to all firefox profiles"
ForEach ($file in ($pKCSFiles)) {
If ((get-content $file -tail 2) -notmatch "PKCS 11") {
$toAppend | Out-File -Append $file -Encoding 'Ascii'
}
}
}
else {
Write-Log "AWP doesn't seem to be installed. Please install Oberthur Authentic web pack before activating this module."
Exit-Script ExitCode 1
}
Также ваш сценарий добавляет к файлам pkcs11.txt только те текстовые файлы, которые вы запрашиваете
Следующий код идентичен приведенному выше, но вместо этого считывает весь файл дляпроверка, а не только конец файла.
# Check to see if AWP is actually installed
$awpPath = "C:\Program Files\Middleware\Card"
$aWPExists = Test-Path $awpPath
$toAppend = "
library=C:\Program Files\Middleware\middleware.dll
name=PKCS 11 Middleware
"
# If AWP Exists copy the pkcs11.txt file to all Firefox Profiles found.
$pKCSFiles = Get-ChildItem -Path 'C:\Users\*\AppData\Roaming\Mozilla\Firefox\Profiles\*\pkcs11.txt'
If ($aWPExists -eq $True) {
Write-Log "AWP Exists and module wasn't found in the pkcs11.txt file. Copying pkcs11.txt to all firefox profiles"
ForEach ($file in ($pKCSFiles)) {
If ((get-content $file -raw) -notmatch "PKCS 11") {
$toAppend | Out-File -Append $file -Encoding 'Ascii'
}
}
}
else {
Write-Log "AWP doesn't seem to be installed. Please install web pack before activating this module."
Exit-Script ExitCode 1
}
Последний и последний вариант, который наиболее логичен.Это заставляет его найти строку.И если этого не произойдет, он добавит его.Прежде чем он заставил его НЕ найти строку.И так как файл состоит из нескольких строк, он все же успешно.
# Check to see if AWP is actually installed
$awpPath = "C:\Program Files\Middleware\Card"
$aWPExists = Test-Path $awpPath
$toAppend = "
library=C:\Program Files\Middleware\middleware.dll
name=PKCS 11 Middleware
"
# If AWP Exists copy the pkcs11.txt file to all Firefox Profiles found.
$pKCSFiles = Get-ChildItem -Path 'C:\Users\*\AppData\Roaming\Mozilla\Firefox\Profiles\*\pkcs11.txt'
If ($aWPExists -eq $True) {
Write-Log "AWP Exists and module wasn't found in the pkcs11.txt file. Copying pkcs11.txt to all firefox profiles"
ForEach ($file in ($pKCSFiles)) {
If (!((get-content $file) -match "PKCS 11")) {
$toAppend | Out-File -Append $file -Encoding 'Ascii'
}
}
}
else {
Write-Log "AWP doesn't seem to be installed. Please install web pack before activating this module."
Exit-Script ExitCode 1
}