相关疑难解决方法(0)

如何在PowerShell中创建数组?

我想在PowerShell中创建一个数组数组.

$x = @(
    @(1,2,3),
    @(4,5,6)
)
Run Code Online (Sandbox Code Playgroud)

它工作正常.但是,有时我在数组列表中只有一个数组.在这种情况下,PowerShell会忽略其中一个列表:

$x = @(
    @(1,2,3)
)

$x[0][0] # Should return 1
Unable to index into an object of type System.Int32.
At line:1 char:7
+ $a[0][ <<<< 0]
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex
Run Code Online (Sandbox Code Playgroud)

如何创建一个数组数组,保证它仍然是一个二维数组,即使数组中只有一个数组项?

arrays powershell

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

如何向自定义对象添加更多属性值

如果我这样做

$account = New-Object -TypeName psobject -Property @{User="Jimbo"; Password="1234"}
Run Code Online (Sandbox Code Playgroud)

如何在不覆盖现有值的情况下添加其他用户和密码值$account

我不能预先填充$account哈希表.我不知道运行时的所有用户和密码.

powershell object

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

New-Object上的Windows RT Powershell(PermissionDenied)

我试图在Powershell中为Windows RT实例化一个对象,但不断收到以下错误.

PS > $foo = New-Object System.Security.Cryptography.SHA1Managed
New-Object : Cannot create type. Only core types are supported in this language mode.
At line:1 char:8
+ $foo = New-Object System.Security.Cryptography.SHA1Managed
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (:) [New-Object], PSNotSupportedException
    + FullyQualifiedErrorId : CannotCreateTypeConstrainedLanguage,Microsoft.PowerShell.Commands.NewObjectCommand
Run Code Online (Sandbox Code Playgroud)

我只花了最后三十分钟搞了一些非常沉重的谷歌,并且找不到任何与类似问题相近的东西,更不用说答案了.我希望我只需要配置一些东西; 我担心Windows RT会附带一个残缺的Powershell版本.

有谁知道它是哪种情况?

powershell

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

标签 统计

powershell ×3

arrays ×1

object ×1