This sample demonstrates cmdlet to create VM on Azure Stack.
- Install
- Download Module Azurestack Tools
- Set Execution Policy
- Set Environment
- Login
- Create Resource Group
- Create Storage Account Name And The Storage Account SKU
- Create A Storage Container To Store The Virtual Machine Image
# Install the AzureRM.Bootstrapper module. Select Yes when prompted to install NuGet
Install-Module `
-Name AzureRm.BootStrapper
# Install and import the API Version Profile required by Azure Stack into the current PowerShell session.
Use-AzureRmProfile `
-Profile 2017-03-09-profile -Force
Install-Module `
-Name AzureStack `
-RequiredVersion 1.2.11
# For Azure Stack development kit, this value is set to https://management.local.azurestack.external. To get this value for Azure Stack integrated systems, contact your service provider.
$ArmEndpoint = "https://management.jkt.cbncloud.co.id"
# For Azure Stack development kit, this value is set to https://graph.windows.net/. To get this value for Azure Stack integrated systems, contact your service provider.
$GraphAudience = "https://graph.windows.net"
# Register an AzureRM environment that targets your Azure Stack instance
Add-AzureRMEnvironment `
-Name "AzureStackUser" `
-ArmEndpoint $ArmEndpoint
# Set the GraphEndpointResourceId value
Set-AzureRmEnvironment `
-Name "AzureStackUser" `
-GraphAudience $GraphAudience
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
# Change directory to the root directory.
cd \
# Download the tools archive.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
invoke-webrequest `
https://github.com/Azure/AzureStack-Tools/archive/master.zip `
-OutFile master.zip
# Expand the downloaded files.
expand-archive master.zip `
-DestinationPath . `
-Force
# Change to the tools directory.
cd AzureStack-Tools-master
if you don't have service principal, you must create a service pricinpal in azurecloud. this is simple code create principal with power shell.
# Create an CBNCloud Deploy Application in Active Directory
Write-Output "Creating AAD application..."
$password = '$password&*';
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$azureAdApplication = New-AzureRmADApplication -DisplayName "Cbncloud Deploy" -HomePage "https://www.cbncloud.co.id" -IdentifierUris "https://www.cbncloud.co.id" -Password $securePassword
$azureAdApplication | Format-Table
# Create the Service Principal
Write-Output "Creating AAD service principal..."
$servicePrincipal = New-AzureRmADServicePrincipal -ApplicationId $azureAdApplication.ApplicationId
$servicePrincipal | Format-Table
# Sleep, to Ensure the Service Principal is Actually Created
Write-Output "Sleeping for 10s to give the service principal a chance to finish creating..."
Start-Sleep -s 10
# Assign the Service Principal the Contributor Role to the Subscription.
# Roles can be Granted at the Resource Group Level if Desired.
Write-Output "Assigning the Contributor role to the service principal..."
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $azureAdApplication.ApplicationId
# The Application ID (aka Client ID) will be Required When Creating the Account in CBNCloud Deploy
Write-Output "Client ID: $($azureAdApplication.ApplicationId)"
if you have service principal
# login azurestack
$userId = "contoso@contoso.onmicrosoft.com"
$password = ("contosoadadeh12398!78*" | ConvertTo-SecureString -AsPlainText -Force)
$tenant_id = "988588549923-094028523-kiodfsgi-023423941";
#Set the powershell credential object
$cred = New-Object -TypeName System.Management.Automation.PSCredential($userId ,$password)
Login-AzureRmAccount -Environment "AzureStackUser" -Credential $cred -TenantId $tenant_id
if you don't know tenant_id, you can this code to powershell
$tenant_id = Get-AzureRmSubscription
# login azurestack
Login-AzureRmAccount -Environment "AzureStackUser"
# Now save your context locally (Force will overwrite if there)
$path = "E:\ProfileAzureStack.ctx"
Save-AzureRmContext -Path $path -Force
if you have a file ProfileAzureStack already occupied, you can load this file
$path = "E:\ProfileAzureStack.ctx"
Import-AzureRmContext -Path $path
# Create variables to store the location and resource group names.
$location = "jkt"
$ResourceGroupName = "myResourceGroup"
New-AzureRmResourceGroup `
-Name $ResourceGroupName `
-Location $location `
-Verbose
$StorageAccountName = "mystorageaccount5"
$SkuName = "Standard_LRS"
# Create a new storage account
$StorageAccount = New-AzureRMStorageAccount `
-Location $location `
-ResourceGroupName $ResourceGroupName `
-Type $SkuName `
-Name $StorageAccountName `
-Verbose
Set-AzureRmCurrentStorageAccount `
-StorageAccountName $storageAccountName `
-ResourceGroupName $resourceGroupName `
-Verbose
$containerName = "osdisk$(Get-Random)"
$container = New-AzureStorageContainer `
-Name $containerName `
-Permission Blob `
-Verbose
-
Full Scripting Create vm no template azurestack https://github.com/CBNCloud/template-azure-stack/blob/master/powershell/create-template-no-template.ps1
-
Full Scripting Create vm with template azurestack https://github.com/CBNCloud/template-azure-stack/blob/master/powershell/create-template-with-template-powershell.ps1
-
Full Scripting Installasi PowerShell template azurestack https://github.com/CBNCloud/template-azure-stack/blob/master/installasi/power.ps1
- Full Scripting Create vm no template Azurecloud https://github.com/CBNCloud/template-azure-stack/blob/master/azurecloud/azurecloud.ps1
The AzureStack is open-sourced software licensed under the MIT license