所以,我发现了一个奇怪的现象:
我有这些头衔导入CSV文件:PowerShell的变量,CSV对象申报
$connections | Get-Member
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Access Method NoteProperty System.String Access Method=SSH
Accessable NoteProperty System.String Accessable=N/A
Application NoteProperty System.String Application=Test
Authentication type NoteProperty System.String Authentication type=rsa
Node NoteProperty System.String Node=ComputerName
Port NoteProperty System.String Port=22
User NoteProperty System.String User=User
现在,如果我提出一个新的变量从一行
$x = $connections[0]
然后改变一些东西在$ X
$x.Accessable = $true
变化会在$ connections [0]中可见。
$connections[0].Accessable
True
这是正常行为吗?如果是这样,我怎样才能创建一个新的变量与该行的类似对象?
编辑: Powershell array assignment assigns variable, not value?是关于数组或多维数组,这个问题是关于对象传输(复制)的。这个页面上的简单答案在这种情况下不起作用。问题仍然存在。
不完全重复IMO。部分问题“如何处理这个特定的对象”在那里没有回答。 – PetSerAl
它是重复的,因为它是关于复制的参考。重复有一个解决方案。虽然这个问题也包含一个替代方案。 – JasonMArcher