我在使用Get-Variable引用對象屬性而不使用。
任何人都知道如何做到這一點?通過變量引用對象屬性
$myObject = New-Object -TypeName PSObject -Property @{
url = 'TESTURL'
webResponse = ''
}
$objName = 'myObject'
Write-Host Attempt1
(Get-Variable -Name $objName -ValueOnly).url # this works, yields TESTURL.
Write-Host Attempt2
$($objName).url # this fails, $($objName) returns a string instead of an object
我期待$($objName)
返回一個對象,但它返回一個字符串代替。
嘛,當然,$ objname是你的對象的名稱。 '$ myObject.url'應該可以工作。 – ESG