Skip to content

Instantly share code, notes, and snippets.

View pkirch's full-sized avatar

Peter Kirchner pkirch

View GitHub Profile
@pkirch
pkirch / MVA03-Images.ps1
Last active August 29, 2015 14:13
This sample shows how to get images available in an Azure subscription.
# sample 1
$images = Get-AzureVMImage
$images.Count
$images[0]
# sample 2
$images | Group-Object -Property OS
# sample 3
$images | Group-Object -Property PublisherName | Sort-Object -Property Name | Format-Table -Property Count, Name -AutoSize
@pkirch
pkirch / MVA04-BlobCopy.ps1
Created January 11, 2015 16:55
This sample show how to copy BLOBs in Azure storage accounts.
# Prepare two storage accounts with three containers source, destination, and backup.
## Copy from current stroage account.
# sample 1
Get-AzureStorageBlob -Container source
Start-AzureStorageBlobCopy -SrcContainer source -SrcBlob test1 -DestContainer destination
# sample 2
Get-AzureStorageBlob -Container source -Blob "*.vhd" | Start-AzureStorageBlobCopy -DestContainer destination
@pkirch
pkirch / MVA05-BlobSnapshot.ps1
Last active August 29, 2015 14:13
This sample shows how to create snapshos of BLOBs in Azure storage accounts.
# step 1: get file
$blobFile = Get-AzureStorageBlob -Container source | Where-Object -Property Name -eq "version.txt"
# step 2: create snapshot
$cloudBlob = $blobFile.ICloudBlob
$cloudBlob.CreateSnapshot()
# step 3: get snapshots
$snapshot = Get-AzureStorageBlob -Container source | Where-Object -Property SnapshotTime
@pkirch
pkirch / MVA06-LockedVHDs.ps1
Created January 11, 2015 17:06
This sample shows different ways to get BLOBs who are locked by VMs and how to remove disks.
Set-AzureSubscription -SubscriptionName "MSFT MVA Live" -CurrentStorageAccountName pktest1
# sample 1
$blobs = Get-AzureStorageBlob -Container vhds
$blobs | Format-Table -AutoSize
$disks = Get-AzureDisk | Select-Object -ExpandProperty MediaLink | Select-Object -ExpandProperty AbsoluteUri
$disks
$blobs | Select-Object -ExpandProperty ICloudBlob | Select-Object -ExpandProperty Uri | Select-Object -ExpandProperty AbsoluteUri
@pkirch
pkirch / AzurePowerShellModul.ps1
Created January 12, 2015 13:54
This samples shows how to get the installations path of the PowerShell module for Microsoft Azure and its version.
Get-Module -Name Azure -ListAvailable
<# Output
Verzeichnis: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 0.8.11 Azure {Disable-AzureServiceProjectRemoteDesktop, Enable-AzureMemcacheRole, Enable-AzureServiceProjectRemoteDesktop...
@pkirch
pkirch / ImportPublishSettingsFile.ps1
Created January 19, 2015 07:49
This sample code shows the usage of Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile.
Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile 'C:\Users\pkirch\Downloads\Azure MSDN - pkirchner-11-20-2014-credentials.publishsettings'
<# Output
Id : c6244819-a8d6-4279-b492-4a47f4301c54
Name : Azure MSDN - pkirchner
Environment : AzureCloud
Account : 8BC957EA7D9DA18CCEFB1E3DD820A0ECD43C8060
@pkirch
pkirch / GetAzureSubscription.ps1
Last active August 29, 2015 14:13
This sample shows the usage of Get-AzureSubscription.
Get-AzureSubscription
<# Output
SubscriptionId : c6244819-a8d6-4279-b492-4a47f4301c54
SubscriptionName : Azure MSDN - pkirchner
Environment : AzureCloud
SupportedModes : AzureServiceManagement
DefaultAccount : 914193B3332ED5FFF26CECABB522B42AA08EDB0E
Accounts : {914193B3332ED5FFF26CECABB522B42AA08EDB0E, 8BC857EA6D9DA18CCEFB2E3DD820A1ECD43C8060}
@pkirch
pkirch / SetAzureSubscriptionCert.ps1
Created January 19, 2015 07:56
This sample shows how to get a certificate and connect it to an Azure subscription.
# Get certificate from personal certificate store.
$cert = Get-Item Cert:\CurrentUser\My\096E6A67C50C4BCED9E27D51013CA92272F73FCD
# Add Azure subscription parameter set including name, ID, and certificate.
Set-AzureSubscription -SubscriptionName "Azure MSDN - pkirchner" -SubscriptionId c6244819-a8d6-4279-b492-4a47f4301c54 -Certificate $cert
# No output
@pkirch
pkirch / Azure MSDN - pkirchner-12-8-2014-credentials.publishsettings
Created January 19, 2015 08:02
Sample of an Azure publish settings file. (ID and management certificate invalidated.)
<?xml version="1.0" encoding="utf-8"?>
<PublishData>
<PublishProfile
SchemaVersion="2.0"
PublishMethod="AzureServiceManagementAPI">
<Subscription
ServiceManagementUrl="https://management.core.windows.net"
Id="c6244819-a8d6-4279-b492-4a47f4301c54"
Name="Azure MSDN - pkirchner"
ManagementCertificate="MIIKFAIBAzCCCdQGCSqGSIb3DQEHAaCCCcUEggnBMIIJvTCCBe4GCSqGSIb3DQEHAaCCBd8EggXbMIIF1zCCBdMGCyqGSIb3DQEMCgECoIIE7jCCBOowHAYKKoZIhvcNAQwBAzAOBAhuTdbdjovtNAICB9AEggTILRDqrkle82JkZdmlABtL+UYHLvzorYcnqfkj5Aa7CbUN2YQpsDgE5GTIst3A0Lj5w/25pqvT0zOIxL/oaDyqtMuAmOniu7IO+FMlOZfFkQFuayX24U83+qd/8429q8TBo/XxaGxOO1mF45embOcZN4snbp60eTs/doE/CSd+H6FrMEKyUecqE467nOXFW2pfg/7ONjZU1CJVsLtp19OZwZsZwxHsxpI7k7iD2R8rnONOK1c9fyKnv9ETcv6vcoMLvAxk0miwufQAUMePRh2zMcgJZLyZurtl+xeYppHZMMW6BW6uVOMgRsbJq3BVGX8JH4hoxpd07BALh5jPzbLjt9pJvkcPwB2zuDIHn4bErxLCD8vpBMaSPScrIUUwRk2nJ3xB+lkGL5dVS8W8nDt76PNlWbWfMGm9Vbtql4oKshsYNsb1EaFYD1ZHitvqI+3NiFnr5z0e2j3+fSDs5+dKWqdkuTpBx2IXt+j7QAx+ysthVyJzHwBTdxvS8jnQ7EFYluzs4o0Wm9+g5U
@pkirch
pkirch / Copy-SystemCenterInfrastructure.ps1
Last active August 29, 2015 14:14
Script for IT Camp Hybrid IT.
# Script created by Peter Kirchner (peter.kirchner@microsoft.com); changed last on 23.04.2015. Based on script by Patrick Heyde (patrick.heyde@microsoft.com).
# The most current version of this script can be found at GitHub Gist: https://gist.github.com/pkirch/695eb59a532265a5dd55
# Description:
# This script sample is part of the IT Camps Hybrid IT in Germany.
# This script copies VHDs from a source storage account into a destination storage account,
# registers the VHDs as disks, imports VM configuration files and starts the VMs.
# Finally the script creates a subfolder in the configuration files folder and stores
# RDP files to the newly created VMs.
#region Settings