0

我有一个文本文件,我想从该文件中删除特殊字符。例如:- 文本文件中的条目

++Mathematics
--Chemistry
(Physics)
$#History)
%%Geography

现在我想替换文本文件中字符串中的所有特殊字符,并希望输出为:-数学化学物理历史地理

我在我的 powershell 脚本中使用了 replace 命令,但是尽管替换了特殊字符,它还是从我的文本文件中删除了所有值。

get-content D:\Share\SCCM-Powershell_Commands\edit.txt
Foreach-object {$_ -replace "\&", "" -replace "\£", "" -replace "\+", "" -replace "\-", "" -replace "\)","" -replace "\(","" -replace "\$","" -replace "\#","" -replace "\*",""}|
Set-Content D:\Share\SCCM-Powershell_Commands\edit1.txt

get-content D:\Share\SCCM-Powershell_Commands\edit.txt

同时有人也可以建议如何开始学习powershell。我是 powershell 的新手,想学习 Powershell 脚本。

4

1 回答 1

0

尝试这样的事情:

foreach ($line in (Get-Content D:\Share\SCCM-Powershell_Commands\edit.txt)) {
    $line -replace "\&", "" -replace "\£", "" -replace "\+", "" -replace "\-", "" -replace "\)","" -replace "\(","" -replace "\$","" -replace "\#","" -replace "\*","" -replace "\%",""
} | Set-Content D:\Share\SCCM-Powershell_Commands\edit1.txt

Get-Content D:\Share\SCCM-Powershell_Commands\edit1.txt
于 2013-11-19T16:32:43.157 回答