繁体   English   中英

如何在Powershell的选择字符串中传递变量

[英]How to pass a variable in the select-string of powershell

有一个要求,我需要将在powershell中设置的变量传递给另一个变量

请找到以下示例

    PS D:\temp\arun> $match1=get-date -format ddMMM
    PS D:\temp\arun> $match1
    19Jun

test.txt文件具有以下内容

    19Jun1
    19Jun2
    19Jun3

    PS D:\temp\arun> $match2=select-string -simple 19Jun test.txt
    PS D:\temp\arun> $match2
    19Jun1
    19Jun2
    19Jun3

但是,当我尝试传递变量时,我没有得到结果。

    PS D:\temp\arun> $match2=select-string -simple $match1 test.txt
    PS D:\temp\arun> $match2

有人可以帮我吗?

在这里工作正常。 尝试指定参数,以确保将正确的值分配给正确的参数。

$match2 = Select-String -SimpleMatch -Pattern $match1 -Path .\test.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM