이하 Azure에 PowerShell을 통해 연결되어있는 동안 작동하는 스크립트가 있습니다 (Azure 계정이 있는지 테스트 할 수 있도록). 상단에 Azure 저장소 계정 목록을 수집합니다. 선택하고 동시에 발견 한 각 저장 계정에 대한 변수 ($ A, $ B, $ C, $ D 등)를 만듭니다. 답변 섹션 아래의 My variable $ StorageSelection은 그 중 하나 (예 : 그러나 $ B는 변수이기 때문에 $ B를 직접 실행하지 않고 $ B의 값을 가진 $ StorageSelection을 실행할 수 있고 $ B의 값을 $를 표시하는 변수처럼 취급하고 싶습니다. B의 가치. 그것은 $ StorageSelection의 값을 변수로 변환하고 동시에 실행합니다. 죄송합니다. 혼란 스러울 지 모르겠지만 몇 시간 동안 내 머리를 짚으 려하고 있습니다.PowerShell 중첩 변수, 값을 변수로 처리
do {
$AzureStorageAccount = Get-AzureStorageAccount
$StorageCount = ($AzureStorageAccount | Measure).Count
write-host ""
write-host "Choose a storage account"
write-host ""
$StorageNumber = 0
do {
$StepAzureStorageAccount = $AzureStorageAccount | select -Skip $StorageNumber | select -First
$GatherStorageAccountName = ($StepAzureStorageAccount).StorageAccountName
$GatherLocation = @(if (($StepAzureStorageAccount).Location -ne $null) {($StepAzureStorageAccount).Location} `
else {($StepAzureStorageAccount).AffinityGroup})
$StorageLetter = $([char](65 + $StorageNumber))
New-Variable -Name "${StorageLetter}" -Value $StepAzureStorageAccount -Force
write-host $StorageLetter" - "$GatherStorageAccountName", "$GatherLocation
$StorageNumber++
}
while ($StorageNumber -lt $StorageCount)
write-host ""
write-host "X - Exit"
write-host ""
write-host -nonewline "Type your choice and press Enter: "
$choice = read-host
write-host ""
$ok = $choice -like '*'
if (-not $ok) { write-host "Invalid selection" }
} until ($ok)
New-Variable -Name "${choice}" -Value $StorageSelection -Force
$storage = $StorageSelection
write-host "You entered"($Storage).StorageAccountName""
어디에서'$ StorageSelection'을 정의합니까? 나는 당신이 그것을 사용하는 것을 본다, 그러나 나는 그것이 창조 된 곳을 보지 못했다. –
세번째 마지막 줄에 정의되어있다. –
세번째 줄부터 마지막 줄까지는'$ {choice}'의 값에서 파생 된 이름을 가진 변수를 정의한 다음 (''B ''),'$ StorageSelection '. 그 결과는'$ B = $ null'입니다. –