小编far*_*rag的帖子

如何使用 PowerShell 替换多个字符串

我想用另外 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
Run Code Online (Sandbox Code Playgroud)

但文件中的每个字符串都被重复了 4 次。脚本将用于 PowerShell 4 和 5.1。

powershell

4
推荐指数
1
解决办法
1万
查看次数

通过 PowerShell 设置 REG_NONE 值

New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\OpenWithProgids -Name Paint.Picture -Type None -Value ([byte[]]::new(0)) -Force
Run Code Online (Sandbox Code Playgroud)

在 Windows 10 中可以运行,但在 Windows 8.1 中存在问题。

powershell

2
推荐指数
1
解决办法
2478
查看次数

标签 统计

powershell ×2