Skip to content

Instantly share code, notes, and snippets.

@dfrankel33
Created December 1, 2016 15:36
Show Gist options
  • Save dfrankel33/eb85621bc9fb8acf0543fcce534408ce to your computer and use it in GitHub Desktop.
Save dfrankel33/eb85621bc9fb8acf0543fcce534408ce to your computer and use it in GitHub Desktop.
# ---
# RightScript Name: Azure - Set Static IP - Windows
# Description: Make a IP static for azure
# Inputs:
# AZURE_ACCOUNT:
# Category: Azure
# Description: AzureAD username
# Input Type: single
# Required: true
# Advanced: false
# Default: cred:AZURE_USERNAME
# AZURE_PASSWORD:
# Category: Azure
# Description: AzureAD password
# Input Type: single
# Required: true
# Advanced: false
# Default: cred:AZURE_PASSWORD
# SUBSCRIPTION_ID:
# Category: Azure
# Description: Azure Subscription ID
# Input Type: single
# Required: true
# Advanced: false
# Default: cred:AZURE_SUBSCRIPTION_ID
# Attachments: []
# ...
$securePassword = ConvertTo-SecureString $ENV:AZURE_PASSWORD -AsPlainText -Force
$azureCredential = New-Object System.Management.Automation.PSCredential ($ENV:AZURE_ACCOUNT, $securePassword)
try {
Add-AzureRMAccount -Credential $azureCredential
}
catch {
Write-Output "Error: Could not add Azure Account!"
EXIT 1
}
$subscriptionID = $env:SUBSCRIPTION_ID
Select-AzureRMSubscription -subscriptionId $subscriptionID
$vm = Get-AzureRMVm | Where-Object {$_.OSProfile.ComputerName -eq $env:computername}
$nic = Get-AzureRmNetworkInterface | where {$_.Id -eq $vm.NetworkProfile.NetworkInterfaces.Id}
$nic.IpConfigurations[0].PrivateIpAllocationMethod = "Static"
Set-AzureRmNetworkInterface -NetworkInterface #nic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment