IT Consultant Everyday Notes

Just some problems/solutions storage

Category Archives: PowerShell

Azure: Migrate an Azure VM v2 (ARM-based) between two storage accounts

One of my Customers asked me to move some VMs from expensive Premium storage account to a cheaper Standard tier.

The infrastructure was built using Resource Mode and luckily we do not need to convert VHDs to OS disks (as it is required for Classic VMs).

1. I shutdown/deprovision VM (you do not need to delete it)

2. Copy VHD OS disk and data disk to the new storage account

3. Recreate VM at the new place using the following script:

Login-AzureRmAccount
select-azurermsubscription -SubscriptionName “My Subscription”

$rgName=”Resourcegroupname”
$locName=”EastUS”
$vnetName=”vnet_name”

# to check subnet index use:   Get-AzureRmVirtualNetwork -Name msps –ResourceGroupName $rgName | Select Subnets
$subnetIndex=1
$name=”yourvmname”

$vnet=Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgName

$vm=New-AzureRmVMConfig -VMName $name -VMSize Standard_D4
$vm | Set-AzureRmVMOSDisk -VhdUri https://*******.vhd –Name $name -CreateOption attach -Windows -Caching ReadWrite

$vm | Add-AzureRMVMDataDisk -Name “XXXX-data” -VhdUri https://*****-data01.vhd -LUN 0 -Caching ReadWrite -CreateOption Attach -DiskSizeinGB 1023

$nicName= $name + “_nic”
$pipName= $name + “_pip”
$domName= $name
$pip=New-AzureRmPublicIpAddress -Name $pipName –ResourceGroupName $rgName-DomainNameLabel $domName -Location $locName -AllocationMethod Dynamic
$nic=New-AzureRmNetworkInterface -Name $nicName –ResourceGroupName $rgName-Location $locName -SubnetId $vnet.Subnets[$subnetIndex].Id -PublicIpAddressId $pip.Id -PrivateIpAddress $privIP
$vm=Add-AzureRmVMNetworkInterface -VM $vm  -Id $nic.Id

New-AzureRMVM -ResourceGroupName Sharepoint -Location “East US” -VM $vm –Verbose

The machine is recreated and started

here are some useful links I used: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-ps-create-preconfigure-windows-resource-manager-vms/

if you have a lot of numbered disks: http://sc.scomurr.com/arm-recreating-vm-off-existing-vhds/

Microsoft doc: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-create-windows-powershell-resource-manager/

PowerShell: PowerShell ISE stopped to work

Issue: PowerShell ISE stopped to work. Pop ups the following error:

The application cannot start because it could not access the user settings file: ‘C:\Users\USERNAME\AppData\Local\Microsoft_Corporation\powershell_ise.exe_StrongName_lw2v2vm3wmtzzpebq33gybmeoxukb04w\3.0.0.0\user.config’

Resolution: I renamed the file on the path indicated in the error and ISE recreated one on the next start

 

Original solution was found here

SCCM 2012: Automatic installation script(s)

Raphael, one of MVPs is developing a PowerShell script suite for SCCM installation automation.

Project is here:  http://cm12automation.codeplex.com/. How-to is here: http://wmug.co.uk/wmug/b/dotraphael/archive/2012/09/28/project-cm12-automation-beta-is-coming.aspx

SCCM 2012 Powershell: You must use 32-bit!

Rafael has a nice post about using PowerShell in SCCM 2012 SP1 (beta). You must actually use 32-bit PowerShell to import module!

More here

PowerShell 3: Install PowerShell Web Access

1. Install feature (here and after all commands in PowerShell console started “As Administrator”!):

Install-WindowsFeature –Name WindowsPowerShellWebAccess –ComputerName <computer_name> IncludeManagementTools –Restart

image

2. Enable PS remoting (if it is not enabled)

Enable-PSRemoting –force

image

3. Configure PSWA using:

Install-PswaWebApplication –UseTestCertificate.

image

4. Add Authorization rule:

image

5. Verify PSWA using access to /pswa">/pswa">https://<server_name>/pswa from Internet Explorer.

image

6. Use PSWA

image

detailed instruction: at Technet site