返回列表 发帖
回复 15# idwma


    前面测试时想到了-notmatch ,刚刚又想到了Add-Content, 但是结果还是没有过滤掉关键字, 关且排序也不是整体的
cd "$HOME\Desktop"
@(
"item"
"Content"
"Process"
) |
%{
$a = $_
Get-Alias | ?{ $_.Definition -notmatch $a } | %{ $_.Definition + ' -> ' + $_.name } | Add-Content "abc.txt"
}COPY

TOP

cd "$HOME\Desktop"
@(
"item"
"Content"
"Process"
) -join '|' |
%{
$a = $_
Get-Alias | ?{ $_.Definition -notmatch $a } | %{ $_.Definition + ' -> ' + $_.name } | Add-Content "abc.txt"
}COPY

TOP

回复 17# idwma


    感谢!
用|合并之后是   item|Content|Process  不用加''吗?
另外, 合并的文件没有按A-Z的顺序排序,之后用 gc | sort | sc  的方法有点麻烦, 有没有更好的办法?

TOP

回复 18# 5i365
@(
"item"
"Content"
"Process"
) -join '|' |
%{
$a = $_
Get-Alias |sort{$_.Definition}| ?{ $_.Definition -notmatch $a } | %{ $_.Definition + ' -> ' + $_.name } | Add-Content "abc.txt"
}COPY
1

评分人数

TOP

本帖最后由 5i365 于 2022-3-25 07:10 编辑

回复 19# idwma


   大侠好, 我把上面改了一下, 定义为了一个函数, 想在显示结果后, 打开在线帮助, 但是死活搞不定, 好像哪个弯没转过来
function gah ($str)
{
        gal |
        where { $_.Name -eq $str } |
        FT -Prop Definition, Name, helpuri -Auto
        start $_.helpuri
}
gah scCOPY

第二种方法, 反过来了, 可以打开帮助, 但是显示的属性表却不对了

function gah ($str)
{
        gal |
        where {
                if ($_.Name -eq $str)
                {
                        $_ | FT -Prop Definition, Name, helpuri -Auto
                        start $_.helpuri
                }
        }
}
gah scCOPY
本人所发所有贴子或代码, 诸大侠若认为有改进之处,请不吝赐教,感激不尽!

TOP

回复 20# 5i365


    为什么要省掉foreach?

TOP

回复 21# idwma


   多谢大侠指教
本人所发所有贴子或代码, 诸大侠若认为有改进之处,请不吝赐教,感激不尽!

TOP

返回列表