小编use*_*807的帖子

$null 应该在等式比较的左侧吗?(-eq 带数组)

和同事讨论,应该$null在支票的左边还是右边?为什么这很重要的任何例子?

$abc = $null
$null -eq $abc
True
$abc -eq $null
True
Run Code Online (Sandbox Code Playgroud)

一切都好

$abc = 6,7,$null,8,9
$null -eq $abc
False
$abc -eq $null
*No output*
Run Code Online (Sandbox Code Playgroud)

有人可以解释比较数组时发生了什么吗?

powershell

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

无法将对象转换为哈希表

我有一个如下所示的哈希表:

$hashtable = @{
    "fruit" = "apple"
    "vegetable" = "carrot"
    "foo" = "bar"
    "test01" = "test"
    "test02" = "test"
    "test03" = "test"
    "test04" = "test"
}
Run Code Online (Sandbox Code Playgroud)

现在我想删除像“Test”这样的条目并创建一个新的哈希表:

[hashtable]$newHashTable = $hashtable.GetEnumerator() | `
Where-Object {$_.Name -notlike "test*"}
Run Code Online (Sandbox Code Playgroud)

这将返回错误: Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Collections.Hashtable".

如何从过滤后的输出创建新的哈希表?

powershell

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

配置深度溢出值 - Start-Job

我有一个递归函数,执行了大约 750 次 - 迭代 XML 文件并进行处理。代码正在运行使用Start-Job

下面的例子:

$job = Start-Job -ScriptBlock {

    function Test-Function {

        Param 
        (
            $count
        )
        Write-Host "Count is: $count"

        $count++
        Test-Function -count $count
    }
    Test-Function -count 1

}
Run Code Online (Sandbox Code Playgroud)

输出:

$job | Receive-Job
Count is: 224
Count is: 225
Count is: 226
Count is: 227
The script failed due to call depth overflow.
Run Code Online (Sandbox Code Playgroud)

在我的机器上,深度溢出始终发生在 227。如果我删除Start-Job,我可以达到 750~(甚至更高)。我正在使用作业进行批处理。

使用时有没有办法配置深度溢出值Start-Job

这是 PowerShell 作业的限制吗?

powershell

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

字符串的百分比比较运算符

我正在学校学习 PowerShell,我有一个关于百分比计算的基本问题:

$foo = "10%"
$bar = "5%"
$foo -gt $bar
False
Run Code Online (Sandbox Code Playgroud)

我尝试转换为整数类型:

[int]$foo -gt [int]$bar
Cannot convert value "10%" to type "System.Int32". 
Error: "Input string was not in a correct format."
Run Code Online (Sandbox Code Playgroud)

PowerShell 中有百分比数据类型吗?或者用于处理百分比的比较运算符?

powershell

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

标签 统计

powershell ×4