0
我對編程非常陌生,我有這樣的代碼。Powershell,Loop,Array有價值,爲什麼Powershell無法識別循環中的有價值
$azuresubscription = get-azuresubscription
for($K = 0; $K -le $azuresubscription.Length -1; $K++){
$s= $azuresubscription[$K]|select SubscriptionName
$s
Write-Host "++++++++++++++++++++";
select-azuresubscription -SubscriptionName $s
}
和回聲出是
SubscriptionName
----------------
CAT
++++++++++++++++++++
select-azuresubscription : Must specify a non-null subscription name.
Parameter name: name
At line:12 char:1
+ select-azuresubscription -SubscriptionName $s
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Select-AzureSubscription], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
Dog
++++++++++++++++++++
select-azuresubscription : Must specify a non-null subscription name.
Parameter name: name
At line:12 char:1
+ select-azuresubscription -SubscriptionName $s
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Select-AzureSubscription], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
Bird
++++++++++++++++++++
select-azuresubscription : Must specify a non-null subscription name.
Parameter name: name
At line:12 char:1
+ select-azuresubscription -SubscriptionName $s
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Select-AzureSubscription], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand
所以我想這樣的
select-azuresubscription -SubscriptionName "CAT"
它的工作原理, 據錯誤,似乎PowerShell的認爲$ s爲null
爲什麼Powershell無法將$ s識別爲CAT,Dog或Bird?我該如何改變它?
主要的是要記住的PS是它的.NET,因此一切都是.NET對象。如果你想要字符串,那就是'-expand'進入的地方。 –