Skip to content

Instantly share code, notes, and snippets.

View markcowl's full-sized avatar

Mark Cowlishaw markcowl

View GitHub Profile
@markcowl
markcowl / Copy-VM-to-ARM.ps1
Created May 19, 2017 16:46
Updated migration script for AzureRM version 4.0
<#
.Synopsis
This script will copy a virtual machine with one or many datadisks from Azure Service Manager to Azure Resource Manager
.DESCRIPTION
This script will copy a virtual machine with one or many datadisks from Azure Service Manager to Azure Resource Manager
.EXAMPLE
Example of how to use this script with no parameters

Converting ServiceClientCredentials to SubscriptionCloudCredentials for Azure Management Clients

When using Azure SDK clients that depend on different runtimes (Microsoft.Azure.Common, Microsoft.Rest.ClientRuntime) together, authentication can be a problem, because the authentication libraries for both runtimes are highly encapsulated, and only one authentication should be required for all the Azure management clients used.

To resolve this, you can use an adapter like the following that converts ServiceClientCredentials (required for the Microsoft.Rest.ClientRuntime clients) to SubscriptionCloudCredentials (required by Microsoft.Azure.Common clients).

Overview

We are making a significant change to the Azure PowerShell cmdlets in the next two releases to resolve a long-standing mismatch between recommended PowerShell practices for confirmation and the default usage of ShouldProcess and ShouldContinue methods and the accompanying Switch Parameter ‘Force’ in Azure PowerShell cmdlets.

The first part of this change, is modeled in this PR Azure/azure-powershell#2535 .

This PR implements confirmation correctly for all cmdlets that currently have a Force parameter. It does not introduce any breaking change for scripts, but it does mark any unnecessary Force parameters as obsolete. These parameters will be removed in phase 2 of this change, in the next (August) sprint. The main impact of this change is to allow PowerShell users to use standard PowerShell tools to discover and control cmdlet processing. The PR also introduces tools to detect violations of correct usage and fail the build if they occur – this will help ensure that

@markcowl
markcowl / gist:4d389e673044c987149b
Created October 13, 2015 22:13
Enable ADAL.Net tracing in PowerShell
Add-Type -Path '<path-to-powershell>\ResourceManager\AzureResourceManager\Resources\Microsoft.IdentityModel.Clients.ActiveDirectory.dll'
[Microsoft.IdentityModel.Clients.ActiveDirectory.AdalTrace]::TraceSource.Switch.Level = [System.Diagnostics.SourceLevels]::All
$listener = New-Object -TypeName System.Diagnostics.TextWriterTraceListener -ArgumentList "<full-path-to-trace-file>"
$listener.Writer.AutoFlush = $true
[Microsoft.IdentityModel.Clients.ActiveDirectory.AdalTrace]::TraceSource.Listeners.Add($listener)
@markcowl
markcowl / gist:95324d3e68947dddf801
Last active August 29, 2015 14:02
Fix Windows Azure PowerShell PSModulePath (broken in 0.8.1, 0.8.2, 0.8.3)
In versions 0.8.1 - 0.8.3 of Windows Azure PowerShell, the installer prepended the value %PSModulePath% to the System environment variable for PSModulePath. This would cause some user-specific PowerShell scripts to be removed from the default path and to no longer be discoverable by default. The attached script fixes the issue. When run from an elevated command prompt it will clean up the machine-wide PSModulePath variable and the PSModulePath in the current session.
This is wrtten as a script. You must have ExecutionPolicy set to RemoteSigned or Unrestricted to run this script. It must be run from an elevated command prompt.
To execute, simply save the script to a ps1 file, like 'FixEnvironment.ps1' and run the script from the command line
> .\FixEnvironment.ps1
The script will prompt before making changes. You can control prompting using the standard parameters (e.g -Force)