Error when executing : Get-Azurestoragecontainer Can not find your azure storage credential. Please set current storage account using “Set-AzureSubscription” or set current storage account using “Set-AzureSubscription” or set the “AZURE_STORAGE_CONNECTION_STRING” environment variable.

When you try to get list of Containers for a given storage account, you might encounter the following error, if default storage account is not set.     Get-AzureStorageContainer : Can not find your azure storage credential. Please set current storage account using “Set-AzureSubscription” or set the “AZURE_STORAGE_CONNECTION_STRING” environment variable. At line:1 char:1 + Get-AzureStorageContainer… Read More Error when executing : Get-Azurestoragecontainer Can not find your azure storage credential. Please set current storage account using “Set-AzureSubscription” or set current storage account using “Set-AzureSubscription” or set the “AZURE_STORAGE_CONNECTION_STRING” environment variable.

Copying image file between subscriptions

[String]$sourcesubID=”ProvideSourcesubscriptionID” [String]$destinationsubID=”ProvideDestinationSubscriptionID” #Source $sourcestorageaccount=”teststorageaccount” $sourcesubscriptionname=”Some Subscription” $sourceimage =”Some sourceimage” $destinationimage=”somedestinationimage.vhd” #destination $destinationAffinityGroup=”GiveDestinationAffinityGroup” $destinationstorageaccount=”destinationstorage” $destinationSubscriptionName=”Some DestinationAzure” $destinationcontainername=”copiedvhd”   #common $thumbprint=’Grab Thumbprint from Azure portal’ #get management certificate $managementCertificate = Get-Item “cert:\CurrentUser\MY\$($thumbprint)” Select-AzureSubscription -SubscriptionName $sourcesubscriptionname Set-AzureSubscription -SubscriptionName $sourcesubscriptionname -SubscriptionId $sourcesubID -Certificate $managementCertificate   #create source storage context $sourcestoragekey = (Get-AzureStorageKey -StorageAccountName $sourcestorageaccount).Primary $sourcestoragecontext = New-AzureStorageContext –StorageAccountName $sourcestorageaccount… Read More Copying image file between subscriptions

Adding Affinity Group and Storage

$adminPassword=”hhhhhhhh” Select-AzureSubscription -SubscriptionName “Azure” New-AzureAffinityGroup -Name “PowerAFG3” -Location “East US” New-AzureStorageAccount -StorageAccountName “PowerStorage3”.ToLower() -AffinityGroup “PowerAFG3”.ToLower() -Label “PowerStorage3”.ToLower() Set-AzureStorageAccount -StorageAccountName “PowerStorage3”.ToLower() -GeoReplicationEnabled $false Set-AzureSubscription -CurrentStorageAccountName “PowerStorage3” -SubscriptionName “Azure xxx” $config=New-AzureVMConfig -Name “MyNewVM” -InstanceSize ExtraSmall -ImageName (Get-AzureVMImage)[4].ImageName $config=$config | Add-AzureProvisioningConfig -Windows -Password $adminPassword -AdminUsername “PsTestAdmin” $config=$config| New-AzureVM -ServiceName “MySvc2” -AffinityGroup “PowerAFG3” -WaitForBoot Get-AzureSubscription | Format-List -Property SubscriptionName,IsDefault,CurrentStorageAccountName… Read More Adding Affinity Group and Storage

Running a ForEach-Object

#Out-GridView -Title “Select a VM to Reset Password” -PassThru Get-AzureVM | Where-Object -Property Status -EQ “ReadyRole” | ForEach-Object { $VM = Get-AzureVM -Name $_.Name -ServiceName $_.ServiceName $VM | Get-AzureDataDisk | Format-list -Property DiskName,LUM,LogicalDiskSizeInGB,MediaLink $VM | Get-AzureOSDisk | Format-list -Property DiskName,LUM,LogicalDiskSizeInGB,MediaLink }

Deleting Virtual MAchine

Deleting an Individual Virtual Machine and Disks from PowerShell The equivelant functionality for the “Delete the attached disks” option from PowerShell is to append the -DeleteVHD parameter onto a call to Remove-AzureVM. Remove-AzureVM -ServiceName $serviceName -Name $vmName -DeleteVHD   Delete the cloud service and its deployments – equivalent PowerShell Code Remove-AzureService -ServiceName $serviceName -DeleteAll Delete… Read More Deleting Virtual MAchine