Skip to content

Instantly share code, notes, and snippets.

@bmoore-msft
Created September 29, 2017 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmoore-msft/51e098b01f1947aa529ebbfff0ee255c to your computer and use it in GitHub Desktop.
Save bmoore-msft/51e098b01f1947aa529ebbfff0ee255c to your computer and use it in GitHub Desktop.
#
#This script will call the validateMoveResources api to see if resources can be moved (before you try to actually move them)
#
$subscriptionId = '...'
$sourceResourceGroup = 'SourceGroup'
$destinationResourceGroup = 'DestGroup' #must exist
# Create an array of resourceIds that are to be moved
$resourcesToMove = @(
"/subscriptions/$subscriptionId/resourceGroups/$sourceResourceGroup/providers/Microsoft.Network/publicIPAddresses/somePublicIp"
"/subscriptions/$subscriptionId/resourceGroups/$sourceResourceGroup/providers/Microsoft.Storage/storageAccounts/somestorageaccount"
)
# Create a hashtable for the request body of the api
$params = New-Object -TypeName Hashtable
$params.Add('resources', $resourcesToMove)
$params.Add('targetResourceGroup', "/subscriptions/$subscriptionId/resourceGroups/$destinationResourceGroup")
# This api will return nothing for success, add the -Debug switch to see the entire REST conversation
Invoke-AzureRmResourceAction -Action validateMoveResources -ResourceId "/subscriptions/$subscriptionId/resourceGroups/$sourceResourceGroup" -Parameters $params -Debug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment