Windows 如何在powershell的select字符串中传递变量

Windows 如何在powershell的select字符串中传递变量,windows,powershell,powershell-2.0,Windows,Powershell,Powershell 2.0,有一个要求,我需要将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 19J

有一个要求,我需要将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

这对我来说就像预期的一样。您的脚本中是否有任何内容可能会干扰$match1或更改其值?您得到的输出@ShayLevy I没有得到任何内容output@ShayLevy当我再次尝试时,它起了作用……很抱歉给您添麻烦。:)快乐现在:)