我想将4个字符串替换为另外4个字符串,并将它们写入文件。
$file = 'C:\Defender.psd1'
(Get-Content $file) | ForEach-Object {
$_.replace("'MSFT_MpSignature.cdxml',", "'MSFT_MpSignature.cdxml')")
$_.replace("'MSFT_MpWDOScan.cdxml')", "")
$_.replace("'Remove-MpThreat',", "'Remove-MpThreat')")
$_.replace("'Start-MpWDOScan')", "") `
} | Out-File $file
但是文件中的每个字符串都被复制了4次,这并不是我们想要的。该脚本将用于PowerShell 4和5.1。