Azure Service

1 Introduction
2 Some simple examples
3 Further Examples

 

1 Introduction

A cloud service is a container for Virtual Machines, Virtual Networks, etc.

 

2 Some simple examples 

Example 1:Information about Cloud Services

Get-AzureService | Select ServiceName,Location
#possible output

ServiceName Location    
----------- --------    
PSPraxis1   North Europe
PSPraxis2   West Europe 
PSPraxis3   West Europe 


Example 2: Simple Creation of a Cloud Service

$ServiceName = "PSPraxis3"
$Label = "myLabel"
$Description = "myDescription"
$Location = "West Europe"
 
New-AzureService -ServiceName $ServiceName -Location $Location 
#possible output

OperationDescription OperationId                          OperationStatus
-------------------- -----------                          ---------------
New-AzureService     49ab7865-e2f6-1166-ad17-8663092fd3ed Succeeded  

 

Example 3:Simple Deletion of a Cloud Service

$AzureServiceName = "PSPraxis2"
$AzureService = Get-AzureService $AzureServiceName
 
$AzureService | Remove-AzureService -Force

#possible Output
 

<..nothing if successfully>

-Force suppresses the confirmation question

 

Example 4:Simple Deletion of Cloud Services with exceptions

Set-StrictMode -Version "2.0"
Clear-Host
Function Main{
  $Exceptions = @("pspraxis1","pspraxis2")
  $CloudServicesToDelete = @(Get-AzureService) | Where {$_.Label -NotIn $Exceptions}
  Delete-AzureService $CloudServicesToDelete
} #End Function Main
 
Function Delete-AzureService{
  Param($CloudServicesToDelete)
  $CloudServicesToDelete  | Remove-AzureService -Force
}#Function Delete-AzureService
 
Main
#possible output

WARNING: 23:38:36 - Removing cloud service PSPraxis3...
WARNING: 23:38:38 - Removing cloud service PSPraxis4...
WARNING: 23:38:40 - Removing cloud service PSPraxis5...

 

3 Further examples

Example 1: Creating a new Cloud Service if it does not exist

Function Main{
  $ServiceName = "PSPraxis1"
  Create-AzureService $ServiceName
}#End Funtion Main
 
Function Create-AzureSerivce{
  Param($ServiceName) 
  If (Test-AzureName -Service $ServiceName){
    Write-Host "Service already exists"
  }Else{
    $Return = New-AzureService -ServiceName $ServiceName -Location "North Europe" -Label $ServiceName 
    If ($Return.OperationStatus -eq "Succeeded"){
      Write-Host "Service $ServiceName has been successfully created" 
    } #$Return.OperationStatus
  }
} #end funtion

Main

#possible output

Service already exists
#Service PSPraxis1 has been successfully created


Example 2: Deleting an existing Cloud Service

Function Main{
  $ServiceName = "PSPraxis1"
  Delete-AzureService $ServiceName
}#End Funtion Main
 
Function Delete-AzureService{
  Param($ServiceName)
  If (Test-AzureName -Service $ServiceName){
      Remove-AzureService -Service $ServiceName -force
      Write-Host "Service $ServiceName has been deleted"
  }Else{
    Write-Host "Service $ServiceName has not been deleted"
  }
}#End Delete-Service

Main
#possible output

Service PSPraxis1 has been successfully created
WARNING: 6:34:29 PM - Removing cloud service PSPraxis1...
Service PSPraxis1 has been deleted

 

Example 3a: Deleting all existing Cloud Services

Function Main{
  Delete-AllAzureServices
}#End Funtion Main

Function Delete-AllAzureServices{
  Get-AzureService | Foreach{
     Remove-AzureService $_.ServiceName -Force
  }#Remove-AzureService $_.ServiceName -force
}#End Delete-AllService

Main
#possible output

WARNING: 6:42:17 PM - Removing cloud service PSPraxis...
WARNING: 6:42:21 PM - Removing cloud service PSPraxis1...
WARNING: 6:42:24 PM - Removing cloud service PSPraxis2...
WARNING: 6:42:27 PM - Removing cloud service PSPraxis3...


Example 3b: Deleting all existing Cloud Services but exceptions

Function Main{
  $Exceptions = @("CloudService001z")
  Delete-AllAzureServices $Exceptions
}#End Funtion Main
 
Function Delete-AllAzureServices{
  Param($Exceptions)
  $ServicesToDelete = @(Get-AzureService) | Where {$_.Label -NotIn $Exceptions}
  $ServicesToDelete | Foreach{
     Remove-AzureService $_.ServiceName -Force
  }#Remove-AzureService 
}#End Delete-AllService
 
Main

 

Example 4: Get Information about a specific Cloud Service

Function Main{
    $ServiceName = "PSPraxis3"
    Get-ServiceInformation $ServiceName
}#End Funtion Main

Function Get-ServiceInformation{
  Param($ServiceName)
  Get-AzureService $ServiceName 
}#End Get-ServiceInformation
#possible output

ServiceName             : PSPraxis3
Url                     : https://management.core.windows.net/dd21..94ad22/services/hostedservices/PSPraxis3
Label                   : PSPraxis3
Description             : 
Location                : North Europe
AffinityGroup           : 
Status                  : Created
ExtendedProperties      : {[ResourceGroup, PSPraxis3], [ResourceLocation, North Europe]}
DateModified            : 8/27/2015 7:14:32 PM
DateCreated             : 8/27/2015 7:14:26 PM
ReverseDnsFqdn          : 
WebWorkerRoleSizes      : {}
VirtualMachineRoleSizes : {}
OperationDescription    : Get-AzureService
OperationId             : c4ca2324-0b25-0fb9-9031-1bf102cb15e7
OperationStatus         : Succeeded

 

Example 5: Get Information about all Azure Services

Function Main{
   Get-AllAzureServices
}#End Funtion Main

Function Get-AllAzureServices{
   Get-AzureService | Select ServiceName,DateCreated
}#End Get-ServiceInformation
#possible output

ServiceName DateCreated         
----------- -----------         
PSPraxis1   8/27/2015 7:19:32 PM
PSPraxis2   8/27/2015 7:19:23 PM
PSPraxis3   8/27/2015 7:14:26 PM