小编Mat*_*man的帖子

New-Object -Property Hashtable没有在Win 10上的5.0版本中填充字段

以下代码在PowerShell 4.0及更早版本中运行良好.如果我在最新的Windows 10版本的5.0.10240.16384版本上运行它,则字段不会填充在新对象($ a)中.这是一个错误还是有变化?

Add-Type @"
   public struct TestUser {
    public string First;
    public string Last;
}
"@;

$a = New-Object TestUser -Property @{ First = "Joe"
                                Last = "Smith"};
Run Code Online (Sandbox Code Playgroud)

版本4.0及更早版本的结果:

$a.First -eq "Joe"
$a.Last -eq "Smith"
Run Code Online (Sandbox Code Playgroud)

5.0版

$a.First -eq $null
$a.Last -eq $null
Run Code Online (Sandbox Code Playgroud)

第5版Get-Member

TypeName: TestUser

Name        MemberType Definition                    
 ----        ---------- ----------                    
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()             
GetType     Method     type GetType()                
ToString    Method     string ToString()             
First       Property   string First {get;set;}       
Last        Property   string Last {get;set;} …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-5.0

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

标签 统计

powershell ×1

powershell-5.0 ×1