我很好奇其他Powershell开发人员在其Powershell配置文件中发现有用的内容。可能性是无穷无尽的。
例如,我经常使用的最强大的Powershell配置文件函数是我的 findTextInWorkspace 函数。我工作的其他开发人员现在开始使用它,因为它被证明非常方便。该函数允许我搜索我的所有本地Powershell脚本以获取特定的文本模式,例如GREP。当脚本在我们的构建服务器上失败时,我可以插入关键字来追踪罪魁祸首。由于我们的应用程序域中有许多重复的脚本和嵌套的文件夹结构,因此该功能可以让我快速找到任何有问题或行为不当的脚本的完整路径。
# find explicit text in all Workspace powershell scripts
function findTextInWorkspace ([string] $text, [string] $path = "C:\Workspace\*")
{
dir $path -recurse -filter '*.ps*1' | Get-ChildItem | select-string -pattern $text | Select-Object Path -Unique
}
然后我可以调用它,就像这样:
cd C:\Workspace\MyApplication
findTextInWorkspace "thisvariablecausedmybuildtocrash" .
我的问题是针对Powershell大师......你在Powershell个人资料中看到或使用过的最强大的“作弊”或强化是什么?我正在寻找有创意和有用的答案。< / p>