相关疑难解决方法(0)

LINQ可以在PowerShell中使用吗?

我试图在PowerShell中使用LINQ.看起来这应该是完全可能的,因为PowerShell是建立在.NET Framework之上的,但我无法让它工作.例如,当我尝试以下(人为的)代码时:

$data = 0..10

[System.Linq.Enumerable]::Where($data, { param($x) $x -gt 5 })
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

无法找到"Where"和参数计数的重载:"2".

不要紧,这可以通过以下方式实现Where-Object.这个问题的关键不是找到在PowerShell中执行此操作的惯用方法.如果我可以使用LINQ,那么PowerShell中的一些任务将更轻松.

linq powershell

44
推荐指数
3
解决办法
2万
查看次数

Powershell:始终生成空文件(比较对象的输出)

此问题最流行的答案涉及以下 Windows powershell 代码(已编辑以修复错误):

$file1 = Get-Content C:\temp\file1.txt  
$file2 = Get-Content C:\temp\file2.txt   
$Diff = Compare-Object $File1 $File2  
$LeftSide = ($Diff | Where-Object {$_.SideIndicator -eq '<='}).InputObject  
$LeftSide | Set-Content C:\temp\file3.txt
Run Code Online (Sandbox Code Playgroud)

我总是得到一个零字节文件作为输出,即使我删除了 $Diff 行。

为什么输出文件总是为空,如何修复?

windows powershell compare file member-enumeration

1
推荐指数
1
解决办法
948
查看次数

标签 统计

powershell ×2

compare ×1

file ×1

linq ×1

member-enumeration ×1

windows ×1