Windows Azure – Exam preperation Links 70-533, 70-532 – Part 4


Staged Deployment on Microsoft Azure Websites

http://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/

New-AzureWebsite

http://msdn.microsoft.com/en-us/library/azure/dn495157.aspx

Azure Web Sites – Continuous Deployment with Staged Publishing

http://ruslany.net/2014/03/azure-web-sites-continuous-deployment-with-staged-publishing/

Azure Powershell Script to list Sites / Staging / Deployment Slots for Web Hosting Plans

http://blogs.msdn.com/b/waws/archive/2014/11/05/azure-powershell-script-to-list-sites-staging-deployment-slots-for-web-hosting-plans-whp.aspx

Azure Websites Web Hosting Plans In-Depth Overview

http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/

Changing Azure Hosting Plans with PowerShell

http://blogs.msdn.com/b/shad_phillips/archive/2014/11/06/changing-azure-hosting-plans-with-powershell.aspx

Creating Azure Web Site using PowerShell

$WebSiteTitle = "TestWebSiteJY"
$Location = "East US"
New-AzureWebsite -Location $Location -Name $WebSiteTitle -
$WebSiteTitle = "azuretestjy123(staging)"
$WebSite = Get-AzureWebSite -Name $WebSiteTitle
$WebSite | Select Name, NetFrameworkVersion, AppSettings

#Adding App Setting to Azure Web Site Staging Slot
$CustomerAppSetting = @{"SiteUrl"="http://portal.contoso.com"}
Set-AzureWebsite $WebSiteTitle -AppSettings $CustomerAppSetting
Restart-AzureWebsite $WebSiteTitle

Enable IIS On Azure VM using Remote PowerShell


With Simple modification you can do anything you want.

 

# Define functions:
Function InstallWinRMCertificateForVM ($servicename, $svrname)
{
    Write-Host "Installing WinRM Certificate for remote access: $servicename $svrname"
    $WinRMCert = (Get-AzureVM -ServiceName $servicename -Name $svrname | select -ExpandProperty vm).DefaultWinRMCertificateThumbprint
	$AzureX509cert = Get-AzureCertificate -ServiceName $servicename -Thumbprint $WinRMCert -ThumbprintAlgorithm sha1

	$certTempFile = [IO.Path]::GetTempFileName()
	$AzureX509cert.Data | Out-File $certTempFile

	# Target The Cert That Needs To Be Imported
	$CertToImport = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certTempFile

	$store = New-Object System.Security.Cryptography.X509Certificates.X509Store "Root", "LocalMachine"
	$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
	$store.Add($CertToImport)
	$store.Close()
	
	Remove-Item $certTempFile
}

$adminUsername  = '<username>'
$adminPassword = '<password>'

$vmname       = "HQServer1"
$cloudsvcName =  "HQServer1"

# Install the WinRM Certificate first to access the VM via Remote PS
InstallWinRMCertificateForVM $cloudsvcName $vmname

# Return back the correct URI for Remote PowerShell
$uri = Get-AzureWinRMUri -ServiceName $cloudsvcName -Name $vmname
$SecurePassword = $adminPassword | ConvertTo-SecureString -AsPlainText -Force
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $adminUsername,$SecurePassword

# Test Remote Script 
Invoke-Command -ConnectionUri $uri.ToString() -Credential $credential -ScriptBlock {
  Get-ChildItem c:\
}

# Install IIS
Invoke-Command -ConnectionUri $uri.ToString() -Credential $credential -ScriptBlock {
  Install-WindowsFeature -Name Web-Server -IncludeManagementTools -Source C:\Windows\WinSxS
}

# Disable Windows Firewall:
Invoke-Command -ConnectionUri $uri.ToString() -Credential $credential -ScriptBlock {
  Set-NetFirewallProfile -All -Enabled False 
}

Assign Availability Set to Existing Azure Virtual Machines


Add-AzureAccount
Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile 'D:\Windows Azure MSDN - Visual Studio Ultimate-12-2-2014-credentials.publishsettings'
Get-AzureSubscription
Set-AzureSubscription -SubscriptionName "Windows Azure MSDN - Visual Studio Ultimate"

$VMHQServer1 = Get-AzureVM -Name HQServer1 -ServiceName "HQServer1"
$VMHQServer1 | Set-AzureAvailabilitySet -AvailabilitySetName WestAvailabilitySet | Update-AzureVM

$VMBranchServer1 = Get-AzureVM -Name BranchServer1 -ServiceName "BranchServer1"
$VMBranchServer1 | Set-AzureAvailabilitySet -AvailabilitySetName WestAvailabilitySet | Update-AzureVM

Get-AzureVM | Select Name, AvailabilitySetName, DNSName

Launch or Save Azure VM Remote Desktop Files using PowerShell


#Get VM Names
$VM1Name = "HQServer1"
$VM2Name = "BranchServer1"
#You can also seperate the Service names if they are different.
#Get VMs
$VM1 = Get-AzureVM -ServiceName $VM1Name -Name "HQServer1"
$VM2 = Get-AzureVM -ServiceName $VM2Name -Name "BranchServer1"
#Save to Desired folders
Get-AzureRemoteDesktopFile -Name $VM1Name -ServiceName $VM1.ServiceName -LocalPath D:\Azure\VM1.rdp
Get-AzureRemoteDesktopFile -Name $VM2Name -ServiceName $VM2.ServiceName -LocalPath D:\Azure\VM2.rdp
#Launch Directly
Get-AzureRemoteDesktopFile -Name $VM1Name -ServiceName $VM1.ServiceName -LocalPath -Launch
Get-AzureRemoteDesktopFile -Name $VM2Name -ServiceName $VM2.ServiceName -LocalPath -Launch

Azure – Creating Storage Account and Uploading VHD using PowerShell


A pretty basic script here.

Create Afinity Group

Create and Get Storage Account

Get Primary keys  and Generate Context

Create a new Container and Upload the VHD.

New-AzureAffinityGroup -Name "2053320532afinitygroup" -Location "East US"
$AfinityGroup = Get-AzureAffinityGroup -Name "2053320532afinitygroup"
New-AzureStorageAccount -StorageAccountName "2053320532storage" -AffinityGroup $AfinityGroup.Name
$StorageAccount = Get-AzureStorageAccount -StorageAccountName "2053320532storage"
$StoragePrimaryKey = (Get-AzureStorageKey -StorageAccountName $StorageAccount.StorageAccountName).Primary
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccount.Label -StorageAccountKey $StoragePrimaryKey

New-AzureStorageContainer -Name "storeddisks1" -Permission Container -Context $StorageContext
$Container = Get-AzureStorageContainer -Name storeddisks1 -Context $StorageContext
$Url = "https://2053320532storage.blob.core.windows.net/storeddisks1/WindowsAzureTest2.vhd"
Add-AzureVhd -LocalFilePath D:\Azure\WindowsAzureTest2.vhd -Destination $Url

Microsoft Azure – Virtual Labs/Demo


http://technet.microsoft.com/en-us/virtuallabs?id=0chXDI/0GGs

Demo 4.1 Provision Microsoft Azure Virtual Machines By Using the Management Portal

http://go.microsoft.com/?linkid=9846267

Demo 6.2 Configure Multi-Factor Authentication in Microsoft Azure Active Directory

http://go.microsoft.com/?linkid=9846277

Demo 6.1 Getting Started with Microsoft Azure Active Directory

http://go.microsoft.com/?linkid=9846276

Demo 5 Monitor Virtual Machines By Using the Management Portal

http://go.microsoft.com/?linkid=9846275

Demo 4.5d Manage Microsoft Azure Virtual Machine Checkpoints By Using Windows PowerShell – Setting up Static IP to Azure VM

http://go.microsoft.com/?linkid=9846274

Demo 4.5c Export and Import Microsoft Azure Virtual Machines By Using Windows PowerShell

http://go.microsoft.com/?linkid=9846273

Demo 4.5a Provision Microsoft Azure Virtual Machines By Using Windows PowerShell

http://go.microsoft.com/?linkid=9846271

Demo 4.5b Configure Microsoft Azure Virtual Machines By Using Windows PowerShell

http://go.microsoft.com/?linkid=9846272

 

Find some other fancy demos below

http://technet.microsoft.com/en-us/virtuallabs?id=0chXDI/0GGs

Basic Office365 Users and Group Management with PowerShell


The script comments will be enought to explain each step.  Its kind of Hello World scripts.  But may help someone for copy paste 🙂

#http://technet.microsoft.com/en-us/library/hh974317.aspx
# First Get the Stuff you need. You do not need a server.  Windows 7, Windows 8 is good enought 🙂 But 64Bit.
#Connecting with Office 365
$CRed = Get-Credential
Connect-MsolService -Credential $CRed

#Listing Users
Get-MsolUser | Select UserPrincipalName, DisplayName, ObjectId

#Listing New User
New-MsolUser -UserPrincipalName "username@domain.onmicrosoft.com" -DisplayName "FirstName LastName" -FirstName "FirstName" -LastName "LastName"

New-MsolUser -UserPrincipalName "testusername@domain.onmicrosoft.com" -DisplayName "FirstName LastName" -FirstName "FirstName" -LastName "LastName"

#Sending to REcyle Bin
Remove-MsolUser -UserPrincipalName "testusername@domain.onmicrosoft.com"

#Restoring the User from Recyle Bin
Restore-MsolUser -UserPrincipalName "testusername@domain.onmicrosoft.com"

#Sending to Permanently Removing
Remove-MsolUser -UserPrincipalName "testusername@domain.onmicrosoft.com" -RemoveFromRecycleBin -Force

#Findig User
Get-MsolUser | ? DisplayName -eq "FirstName LastName" 
Get-MsolUser | ? UserPrincipalName -eq "username@domain.onmicrosoft.com"

#Getting and chaning User information.  Assigning Usage Location to assing Licneses
$TestUser = Get-MsolUser | ? UserPrincipalName -EQ "username@domain.onmicrosoft.com"
Set-MsolUser -ObjectId $TestUser.ObjectId -UsageLocation "US"
Set-MsolUser -ObjectId $TestUser.ObjectId -DisplayName "Changed First, LastName" -FirstName "NewFirstName" -LastName "NewLastName"

#Display Licenses
Get-MsolUser | ft displayname, Licenses

#List the Office 365 Subscription or Sku
Get-MsolAccountSku

#Set the License for User (This will assign all the Available Licenses)
Set-MsolUserLicense -ObjectId $TestUser.ObjectId -AddLicenses (Get-MsolAccountSku).AccountSkuId
Set-MsolUserLicense -UserPrincipalName $TestUser.UserPrincipalName -AddLicenses (Get-MsolAccountSku).AccountSkuId

#DisplayUser Information
Get-MsolUser | ft displayname, Licenses

#List All Plans
Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq "ENTERPRISEPACK"} | ForEach-Object {$_.ServiceStatus}
#YAMMER_ENTERPRISE PendingInput 
#RMS_S_ENTERPRISE Success 
#OFFICESUBSCRIPTION Success 
#MCOSTANDARD Success 
#SHAREPOINTWAC Success 
#SHAREPOINTENTERPRISE Success 
#EXCHANGE_S_ENTERPRISE

#Making a Sub Option object for Selective values
$Options = New-MsolLicenseOptions -AccountSkuId (Get-MsolAccountSku).AccountSkuId -DisabledPlans SHAREPOINTWAC, EXCHANGE_S_ENTERPRISE

#Assigning it user object 
Set-MsolUserLicense -UserPrincipalName $TestUser.UserPrincipalName -LicenseOptions $Options -Verbose

#Creating a New Office 365 Group 
$Group = New-MsolGroup -DisplayName "ATM" -Description "ATM Users"
#Getting the Group
$Group = Get-MsolGroup | ? DisplayName -EQ "ATM"
#Adding Member to Group
Add-MsolGroupMember -GroupObjectId $Group.ObjectId -GroupMemberObjectId $TestUser.ObjectId
Get-MsolGroupMember -GroupObjectId $Group.objectId

#Reading Properties of Users in a Group
Get-MsolGroupMember -GroupObjectId $Group.ObjectId -All | Select ObjectId, DisplayName, EmailAddress

#REmvoing Group Peramentnly - not Recylebin here 🙂
Remove-MsolGroup -ObjectId $Group.ObjectId

#Sampe CSV
#https://portal.office.com/UserManagement/Samples/Import_User_Sample_en.csv
#Blank CSV
#https://portal.office.com/UserManagement/Templates/Import_User_Template_en.csv

#Build Import Users from CSV (Please Remove Formatting if it does not work :))
Import-Csv -Path c:\Users.csv | ForEach-Object 
    { 
        New-MsolUser -UserPrincipalName $_."UPN"   -AlternateEmailAddresses $_."AltEmail" 
                    -FirstName $_."FirstName"     -LastName $_."LastName" 
                    -DisplayName $_."DisplayName" -BlockCredential $False 
                    -ForceChangePassword $False   -LicenseAssignment $_."LicenseAssignment" 
                    -Password $_."Password"       -PasswordNeverExpires $True 
                    -Title $_."Title"             -Department $_."Department" 
                    -Office $_."Office"           -PhoneNumber $_."PhoneNumber" 
                    -MobilePhone $_."MobilePhone" -Fax $_."Fax" 
                    -StreetAddress $_."StreetAddress" -City $_."City" 
                    -State $_."State"                 -PostalCode $_."PostalCode" 
                    -Country $_."Country"             -UsageLocation $_."UsageLocation" 
    }