Created
December 1, 2016 15:36
-
-
Save dfrankel33/eb85621bc9fb8acf0543fcce534408ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- | |
# 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