IT Consultant Everyday Notes

Just some problems/solutions storage

Tag 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/

Advertisements

SCCM 2012: Application Catalog WebService Point failed with “Parameter set cannot be resolved using the specified named parameters.”

 

I tried to install the abovementioned role using Powershell. I followed Microsoft example letter by letter but it still failed with a nasty PowerShell error “Parameter set cannot be resolved using the specified named parameters.”

SNAGHTML53b83032

Finally I found a spreadsheet on http://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&cad=rja&uact=8&ved=0CDYQFjAE&url=http%3A%2F%2Fcm12sdk.net%2F%3Fwpdmact%3Dprocess%26did%3DMTQuaG90bGluaw%3D%3D&ei=ZVvBVMLiMIacyAT174JY&usg=AFQjCNG9mVW1L-nWqtbI813UbYzrFKCXlQ&bvm=bv.83829542,d.aWw

 

and put parameters EXACTLY in the order mentioned there. (I know, it is crazy). Surprisingly, the cmdlet works now .

SNAGHTML53bae000

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

SCOM 2012 R2: Prerequisites installation script

Inspired by this script  by Richard Qi I created a modified version for SCOM 2012 R2 on Windows Server 2012. The difference is Report Viewer 2012 (and its prerequisite – SQL Control Types)

Here is the script content (copy it to .ps1 file and run from Power Shell)

NOTE: ReportViewer URL is updated April 14th 2014

#This section installs the .NET and IIS Prereqs for Windows Server 2012#
Import-Module ServerManager
Add-WindowsFeature NET-Framework-Core,AS-HTTP-Activation,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-Http-Logging,Web-Request-Monitor,Web-Filtering,Web-Stat-Compression,AS-Web-Support,Web-Metabase,Web-Asp-Net,Web-Windows-Auth –restart#This section will download SQL System CLR and the Report Viewer 2012 Runtime Prereq for Windows Server 2008 or Windows Server 2012#
#to a folder called C:\SCOM2012SP1Prereqs. Once the file has been downloaded it will automatically install       #

$dwnld = “C:\SCOM2012SP1Prereqs”
if (!(Test-Path -path $dwnld))
{
New-Item $dwnld -type directory
}
$object = New-Object Net.WebClient

$RPTurl = ‘http://go.microsoft.com/fwlink/?LinkID=239644&clcid=0x409′
$object.DownloadFile($RPTurl, “$dwnld\SQLSysClrTypes.msi”)
Start-Process -FilePath “msiexec.exe” -ArgumentList ” -i $dwnld\SQLSysClrTypes.msi /qb” -Wait

$RPTurl = ‘http://download.microsoft.com/download/F/B/7/FB728406-A1EE-4AB5-9C56-74EB8BDDF2FF/ENU/x86/ReportViewer.msi
$object.DownloadFile($RPTurl, “$dwnld\ReportViewer.msi”)
Start-Process -FilePath “msiexec.exe” -ArgumentList ” -i $dwnld\ReportViewer.msi /qb” -Wait

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