比较两个项目是否与 powershell 匹配

比较两个项目是否与 powershell 匹配

我正在以文本文件形式导出驱动器名称电影。

Get-WmiObject win32_logicaldisk| foreach-object {$volumename -Match "movies" } | select movies > c:\nn.txt

后来进行比较但没有成功,总是得到错误的结果,有人可以帮忙吗?

$test=Get-WmiObject win32_logicaldisk| foreach-object {$volumename -Match "movies" } | select movies > c:\nn.txt
    $array =get-content c:\nn.txt
    $real= Get-WmiObject win32_logicaldisk| foreach-object {$volumename -Match "movies"} | select movies
    If ($array -eq $real)

    {write-host "it was success" -foregroundcolor blue}
    Else {write-host "it was fail" -foregroundcolor green}

答案1

get-wmiobject win32_logicaldisk | ? Volumename -eq "movies" | select -ExpandProperty Volumename | out-file "c:\nn.txt"
$array =get-content  "c:\nn.txt"
$real =  get-wmiobject win32_logicaldisk | ? Volumename -eq "movies" | select -ExpandProperty Volumename
If ($array -eq $real)

{write-host "it was success" -foregroundcolor blue}
Else {write-host "it was fail" -foregroundcolor green}

相关内容