PowerShell ISE自动化简单示例

PowerShell ISE的自动化不依赖与任何第三方的框架和工具,因为PowerShell ISE本身就是可编程的。非常高大上地被称作为PowerShell抽象语法树,其实在之前的一篇文章中有简单分享过。关键点在于$PSISE变量。

今天再来看两行更加单的例子:

我想输出PowerShell ISE 中当前编辑框中的所有脚本:

$psise.CurrentFile.Editor.Text

我想将PowerShell ISE中当前编辑框中的所有脚本中的某个字符串,替换成我期望的字符串,但是不使用PowerShell ISE中本身界面的查找和替换。

$psise.CurrentFile.Editor.Text = $psise .CurrentFile.Editor.Text -replace '官本位' , '民本位'