The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

Archive for the ‘System Center 2012 R2’ Category

Working in the Datacenter – I need to know everything about my VHD’s in my SCVMM environment

Posted by Mikael Nystrom on November 25, 2016

I was asked about getting more information about all the VHDs in a SCVMM environment (you now how you are). It is actually easy to do this, so i created a function that uses the SCVMM PowerShell module to grab all data and does a calculation on the expansion rate in percent for all disks, it pretty much gives you this:

image
Result.

The result will be that you now know where they are, sizes, expansion, type, parents, and some more info as well, and if you know, you can act.

You can grab the module from GitHub: https://github.com/DeploymentBunny/Files/tree/master/Tools/Get-VIASCVMMDiskInfo

/mike

Posted in PowerShell, System Center 2012 R2, System Center 2016, System Center Virtual Machine Manager | Tagged: , , , | Leave a Comment »

Working in the Datacenter – Deploying the DPM agent using PowerShell

Posted by Mikael Nystrom on March 10, 2016

Last night i was deploying a DPM server for a customer and we needed to deploy the DPM agent on a few machines. It is well know that DPM can do push agent install, but the requirements is to open high ports on every client, well lets state that it is not something any customer likes to do, so that means that we will use the Attach Agent function in DPM and that require the agent to be installed first.

The trick is not to install it, rather running the setDpmServer command that will do a connection against the DPM server, resulting in the double hop issue in Windows. The real solution is to use the existing software deployment solution to push the agent or to install the agent when the server is deployed, but in this case we needed a quick-and-dirty method to get it out to a few servers.

So the script will copy the installers to the target, install the agent, configure the agent and add the agent to the DPM server. It works with multiple servers at the same time. It uses CredSSP to fix the double-hop issue, which was ok for this customer.

The Script


Param(
    $Servers,
    $UserName,
    $Password,
    $DMPServerName
)

$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$User = “$env:USERDOMAIN\$UserName”
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $User, $SecurePassword

Foreach($Server in $Servers){
    Enable-WSManCredSSP -Role Client -Force -DelegateComputer $Server 
    New-Item -Path "\\$Server\c$\DPMinstall" -ItemType Directory -Force 
    Copy-Item -Path 'C:\Program Files\Microsoft System Center 2012 R2\DPM\DPM\ProtectionAgents\RA\4.2.1205.0\amd64' -Destination "\\$Server\c$\DPMinstall" -Container -Force -Recurse
    Invoke-Command -ComputerName $Server -ScriptBlock {
        Enable-WSManCredSSP -Role Server -Force
        cmd.exe /c C:\DPMInstall\amd64\DPMAgentInstaller_x64.exe /q /IAcceptEula
        & 'C:\Program Files\Microsoft Data Protection Manager\DPM\bin\SetDpmServer.exe' -dpmServerName $DMPServerName
    } -EnableNetworkAccess -Credential $Credentials -Authentication Credssp
    & 'C:\Program Files\Microsoft System Center 2012 R2\DPM\DPM\bin\Attach-ProductionServer.ps1' -DPMServerName "$DMPServerName.$env:USERDNSDOMAIN" -UserName $UserName -Password $Password -Domain $env:USERDOMAIN -PSName $Server
}

/mike

Posted in Data Protection Manager, Datacenter, System Center 2012 R2 | Tagged: , , | 1 Comment »

Working in the Datacenter – Deploying Update Rollups for System Center 2012 R2

Posted by Mikael Nystrom on November 14, 2015

You really need to understand this: A Update Rollup should NEVER, EVER be deploying using WSUS!!! (or any other automated way, unless you know exactly what needs to be done before and after to make it work)

Why?

Microsoft provides all the Update Rollups trough Windows Update, so far so good, that makes it easy to deploy, so what is the big “nono” here? Well, the short story is that it does not work they way most people assumes. Deploying the Update Rollup could also require you to perform actions like this:

  • Update the SQL database using script
  • Add or modify Registry Keys
  • Manually update Agents
  • Troubleshoot issues

So, based on the history, please, just don’t do this, it does not work. You need to deploying a Update Rollup pretty much like a Service Pack, since that is what it really is. It does contain both bug fixes as well as new features and some of the features will change behavior, some of the new features needs to be enabled.

Ok, so how?

You need to follow the blogs from each product team so you know when they are released and then you need to follow the step-by-step instructions from the team. If you do have a test system (you can use a hydration kit to build one fast and use for testing, check http://www.deploymentbunny.com or http://deploymentresearch.com for more information

Ok, so When?

You have two options here, you either know someone that has tested and verified it or you wait 30 days and “listen” on the Internet, if you see 1.000.000 hits in a search engine, maybe you should wait to everyone else has fixed it.

Plan it a head

Ok, so this is what I tell all the customers I work with. Since Microsoft is releasing Update Rollups 4 times per year, create a schedule and set a side a couple of days (or more) every year to do this. It does not need to match the dates Microsoft will release it, just have a Maintenance Window 4 times every year to update/maintain your System Center platform.

Deploying Update Rollup 8 for System Center 2012 R2 – All Systems

https://support.microsoft.com/en-us/kb/3096378

Deploying Update Rollup 8 for System Center 2012 R2 – App Controller (No updates)

The last update for App Controller was System Center 2012 SP1 – http://support.microsoft.com/kb/2879276

Deploying Update Rollup 8 for System Center 2012 R2 – Data Protection Manager

Note: Could require a restart of all protected servers after deploying agent.

3086084 Update Rollup 8 for System Center 2012 R2 Data Protection Manager

Download the Data Protection Manager update package now

Deploying Update Rollup 8 for System Center 2012 R2 – Operations Manager

Note: Do not install this update rollup package immediately after you install the System Center 2012 R2 server. Otherwise, the Health Service state may not be initialized.

Note: Could require manually editing webpages

Note: Could require you to manually adding Registry Keys and Values

Note: Could require you to manually run SQL scripts to update the database

3096382 Update Rollup 8 for System Center 2012 R2 Operations Manager

Download the Operations Manager update package now

Deploying Update Rollup 8 for System Center 2012 R2 –  Orchestrator

3096381 Update Rollup 8 for System Center 2012 R2 Orchestrator

Download the Orchestrator update package now

Deploying Update Rollup 8 for System Center 2012 R2 – Service Provider Foundation

3096384 Update Rollup 8 for System Center 2012 R2 Service Provider Foundation

Download the Service Provider Foundation update package now

Deploying Update Rollup 8 for System Center 2012 R2 – Virtual Machine Manager

Note: Bare metal provisioning has changed

Note: Could require you to manually run SQL scripts

Note: Many new features, read and understand (and test them)

3096389 Update Rollup 8 for System Center 2012 R2 Virtual Machine Manager

Download the Server update package now

Download the Administrator Console update package now

Download the Guest Agent update package now

Deploying Update Rollup 8 for System Center 2012 R2 – Windows Azure Pack

3096392 Update Rollup 8 for System Center 2012 R2 Windows Azure Pack

Download the Windows Azure Pack update package now

Posted in System Center 2012 R2, Datacenter, Orchestrator, Windows Azure Pack, Virtual Machine Manager, Service Provider Foundation, Operations Manager, Data Protection Manager | Tagged: , , , , , , , , | Leave a Comment »

Nice to Know – Clean up the ISO name mess I SCVMM so that Windows Azure Pack looks nice

Posted by Mikael Nystrom on February 5, 2015

In System Center Virtual Machine Manager there is a library. The library stores resources used in the environment and one kind of resources is ISO images. The problem is that names on those ISO images is slightly “technical” and not so user-friendly. So who cares?

The Issue:

When you start using Windows Azure Pack to provide self-service, that is a very good reason to have nice names here is two samples

imageimage
In the first picture, all the names looks ok, in the second picture, it looks different…

The names of the these files comes from System Center Virtual Machine Manager and they are easy to change, just go in to the library, open each and everyone and change the name…

image
How to modify the name of the ISO resource in the SCVMMLibrary using the UI.

However, doing that for one or two files are ok, more then that, it kind of gets boring after a while.

The Solution:

So, you can export all the information in to a CSV file, modify the CSV file to suit your organization and then import it again.

Export CD/DVD meta data from SCVMM using PowerShell

Get-SCISO -All -VMMServer “clscvm01.cloud.truesec.com” | where HostType -EQ LibraryServer | Select LibraryServer,SharePath,Name,Description | ConvertTo-Csv -NoTypeInformation > “$env:TEMPISOInSCVMMLib.csv”

and that will give something like this:

image
A few of the ISO’s in the SCVMMLibrary.

So, open the file, modify name and description and run this


function Update-ISOForSCVMLib
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$LibraryServer,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
$SharePath,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=2)]
$Name,

[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=3)]
$Description
)
$ISOToUpdate =  Get-SCISO -All | Where LibraryServer -EQ $LibraryServer | Where SharePath -EQ $SharePath
$ISOToUpdate | Set-SCISO -Description $Description -Name $Name
}


This will give you a new function and that new function can be used in the following way.

Import-Csv .\ISOInSCVMMLib.csv | foreach {Update-ISOForSCVMLib $_.LibraryServer -SharePath $_.SharePath -Name $_.Name -Description $_.Description}

The function is going trough the CSV file and search for the file, find the object and finally change the display name of the object.

/mike

Posted in SCVMM, System Center 2012 R2, Virtual Machine Manager | Leave a Comment »

Nice To Know – Generate the -JobGroup ID in SCVMM Scripts

Posted by Mikael Nystrom on January 28, 2015

When working with SCVMM it is common to perform administrative tasks using PowerShell. One very nice thing in SCVMM is that when using the UI it will create a script in the end and the idea is that you should be able to use that script and you can, one time…why?

…because you need to generate a new ID every time you run the script, so how do you do that?

Generate a GUID using PowerShell:

$JobGroupID1 = [Guid]::NewGuid().ToString()

image
The result when generating a GUID.

Using the generated GUID in a SCVMM PowerShell script

Here is a list of CMDlets that uses _JobGroup

https://social.technet.microsoft.com/Forums/systemcenter/en-US/ab1e7054-69c7-44ee-a475-229f9557b653/jobgroup-what-cmdlets?forum=virtualmachinemanager

/mike

Posted in PowerShell, SCVMM, System Center 2012 R2 | Tagged: , , | Leave a Comment »

Nice to Know – Azure Operational Insights -Data aggregation in progress”

Posted by Mikael Nystrom on January 27, 2015

I was troubleshooting Capacity planning Intelligence Pack stuck in “Data aggregation in progress” and found a blog post from the team, one of the best step-by-step’s for troubleshooting this problem I have seen. If you do have issues with this, just follow the guide

If this is your issue:

image

Follow this guide:

image

In this guide check out these procedures:

  • Validate if the right Management Packs get downloaded to your OpsMgr Environment
  • Validate if the right Intelligence Packs get downloaded to your Direct Agent
  • Validate if data is being sent up to the Advisor service (or at last attempted)
  • Check for Errors on the Management Server or Direct Agent Event Logs
  • Look for your agents to send their data and have it indexed in the Portal

Posted in OpsMgr, SCVMM, System Center 2012 R2 | Tagged: | Leave a Comment »

Issue (Hyper-V/SCVMM) – VMM cannot complete the host operation on the HOST server because of error:Storage for virtual machine ‘HOSTNAME’ failed with error ‘The device is not ready.’ (0x80070015)

Posted by Mikael Nystrom on August 28, 2014

Issue:

When trying to migrate a VM’s storage to a local device using SCVMM you could see this:

Error (12700)
VMM cannot complete the host operation on the HOST server because of the error: Storage migration for virtual machine ‘VM’ (GUID) failed with error ‘The device is not ready.’ (0x80070015).

Operation not allowed for virtual machine ‘VM’ because Hyper-V state is yet to be initialized from the virtual machine configuration. Try again in a few minutes.(Virtual machine ID )
Unknown error (0x800c)

When trying to migrate a VM’s storage to a local device using Hyper-V manager you could see this:

"Storage migration for virtual machine"HOST’ failed.
Operation not allowed because the replication state is not initialized.
Storage migration for virtual machine "HOST’ failed with error ‘The device is not ready’ (0x80070015)."

Solution:

So far the only solution I have found, tried (and it did work) is to restart the Hyper-V management service.

http://social.technet.microsoft.com/Forums/systemcenter/en-US/eb4511c5-23f9-4c1e-af32-88de0eeaaef1/vhdx-failed-to-migrate-to-local-storage?forum=virtualmachingmgrhyperv

Posted in SCVMM, System Center 2012 R2, System Center Virtual Machine Manager, System Center Virtual Machine Manager 2012 | Tagged: | Leave a Comment »

Nice to Know – OS Deployment on TechNet – Check This out!!!

Posted by Mikael Nystrom on May 12, 2014

For many years TechNet has been the source of information for IT Pro’s, but in many cases it has been “This is what you could do”, leaving a lot of IT profs in a guessing game. For OS Deployment that has now changed, it is changing into “This is how you should do!” and that is VERY nice!

Go to http://technet.microsoft.com/en-us/windows/hh974336

And check this out ASAP

(And yes, they hired external resources the help them get the best content ever…)

/mike

Posted in Deployment, MDT, System Center 2012 R2, Training, Windows 8.1 | Tagged: | Leave a Comment »

PowerShell is King – Building a Reference Image Factory

Posted by Mikael Nystrom on January 6, 2014

In the world of deployment a reference image is where all begins, basically we take the ISO/WIM from the vendor, install it, tweak it, patch it and on the other side we now a have a customized reference image that is more suitable for our needs. This applies to both clients and servers. There are two ways of doing this, the correct way and the incorrect way. The correct way is repeatable and as automated as possible. This blog is about the correct way and how to automate it just a bit more then usual. You can of coarse modify the script so it will do more, for example upload the images to the correct destination.

Acknowledgement goes to:

What do I need to get this working?

Step 1: Set up Microsoft Deployment Toolkit 2013 on a server

Step 2: Import Operating Systems, applications and create your task sequences

Step 3: Install Windows Server 2012 R2 (or Windows 8.1) with Hyper-V as your “creator”

Step 4: Download the script and enjoy the show

Note:

  • The script is designed to run on the Hyper-V machine, but it is possible to run this remote either using Remote-Sessions or defining –Computer on every Commands that relates to Hyper-V
  • The Solution is tested on Windows Server 2012 R2 with MDT 2013 and ADK 8.1 BUT should work just fine on Windows 8.1

How does the script work?

image

The PowerShell module has a couple of functions

New-AutoGenRefImages

This function will connect to your MDT server, grab the boot ISO, read all TaskSequences from Task Sequences\REF

image

And for each of them build a VM with the same name as the task sequence. When they are all built it will power them on one by one, booting from the ISO and then run the task sequence that corresponds to the name of the the VM. So if you have a TS with the ID of RW81.x86, it will build a VM with that name and run the TS with that ID on that VM.

You might ask your self how that is done?. I’m not using the database, not using GUID number or Mac’s. The main reason is that I want a solution with as little dependencies as possible, so it will work anytime at any customer (almost). Instead I’ loading the drivers for KVP (Key Value Pair Exchange) in WinPE, I grab the name of the VM before the customsettings.ini is read using a userexit script in bootstrap.ini so I have a Property called VMNameAlias wich then is used to control the deployment process, a neat solution IMHO (more on that later)

Remove-AutoGenRefImages

This function will destroy and remove all VMs, it does this by getting all task sequence ID’s from the MDT server, and find corresponding VM’s and then destroy and clean up.

New-RefImage

This is a manual process, you now need to KNOW the Task Sequence ID, since that is a validation in the CMDLET

Remove-RefImage

Also a manual process, it will destroy/delete/cleanup whatever VMname you type in, note that there will be NO questions, it just deletes them, so don’t type in DC01 or something like that.

Get-RefTaskSequence

A simple CMDLET that lists all task sequences that are in the \REF folder in MDT

The Details

Download the Scripts from here: http://sdrv.ms/1hqoJIh

Download devcon.exe from here: http://support.microsoft.com/kb/311272/en-us

Modify ImageFactoryV2.xml

This is my sample XML file and you need to modify it so it will work in your environment.

<Settings>
<DeploymentShare>\\SRVHOST555\MDTBuildLab$</DeploymentShare>
<HyperVHost>SRVHOST555</HyperVHost>
<HyperVHostNetwork>UplinkSwitch</HyperVHostNetwork>
<HyperVStorage>E:\VMs</HyperVStorage>
<HyperVISOFolder>E:\ISO</HyperVISOFolder>
<HardwareProfile>MDT 2010 Profile</HardwareProfile>
<TaskSequenceFolder>MDT:\Task Sequences\REF</TaskSequenceFolder>
<StartUpRAM>2</StartUpRAM>
<VLANID>0</VLANID>
<VHDSize>60</VHDSize>
</Settings>

Modify bootstrap.ini

Bootstrap.ini needs some modification (besides being silent). You need to add the following:

image

In text:

[Settings]
Priority=Default

[Default]
DeployRoot=\\SRVHOST555\MDTBuildLab$
UserDomain=NETWORK
UserID=Administrator
UserPassword=Password02
SkipBDDWelcome=YES
SubSection=ISVM-%IsVM%

[ISVM-True]
UserExit=LoadKVPInWinPE.vbs

This will load a userexit script that installs the driver for KVP and create a fake services that will allow it to load.

Modify customsettings.ini

You need to modify customsettings.ini so it will read in the values from the KVP correctly

image

In text:

[Settings]
Priority=Init,Default
Properties=VMNameAlias

[Init]
UserExit=ReadKVPData.vbs
VMNameAlias=#SetVMNameAlias()#

[Default]
TaskSequenceID=%VMNameAlias%

You need to add the Property VMNameAlias under the Settings Section

You need to create a new Section called Init that runs the UserExit

You need to set the TaskSequenceID to match the returned value from the UserExit script

Modify the boot image:

You need to make sure that those two scripts are added correctly and we also need the driver for KVP. One easy way is to use the “Extra” folder feature in MDT, whatever you put in that folder will end up on the boot image.

My deployment share is located in

E:\MDTBuildLab

so I created a folder called

E:\MDTBuildLab\Extra

In that Folder I two folders, Deploy and KVP. In the folder Deploy I have a subfolder called Scripts.

Like this:

image

Content of the KVP folder:

In the KVP folder you need to add the driver for KVP, and that you can do by searching for VMGuest.iso on your Hyper-V host, it is in C:\Windows\System32, mount that is and extract the drivers.

The driver you need is in the support\x86\Windows6.x-HyperVIntegrationServices-x86.cab and the folder is namned x86_wvmic.inf_31bf3856ad364e35_6.3.9600.16385_none_968283a5680527fe

(read Keith Garners blog for details, Note: In Keith’s blog it is 64 bit, I’m using the 32 bit driver, since I boot from the x86 boot image. Therefore the name is different of course.)

You also need to store devcon.exe in that folder

When you got them, it should look like this in the folder

image

Content of the Deploy\Scripts folder

In this folder you store the LoadKVPinWinPE.vbs script

Like this:

image

Update the BootImage:

In the Boot Image setting for WinPE, for the setting called Extra directory to add, browse to your folder, apply, update boot image.

image

The Scripts:

LoadKVPInWinPE.vbs

Mainly “borrowed” from Keith’s blog, just modified to use devcon.exe instead the method suggested by Keith


option explicit

function UserExit(sType,Swhen,Sdetail,bSkip)
oLogging.CreateEntry “USEREXIT:ModelAliasExit.vbs started: ” & sType & ” ” & sWhen & ” ” & sDetail, LogTypeInfo

    If ucase(oEnvironment.Item(“ISVM”)) = “TRUE” and oEnvironment.Item(“OSVERSION”) = “WinPE” then

        oLogging.CreateEntry “Load the Integration Components”, LogTypeInfo
oUtility.RunWithConsoleLogging “\KVP\devcon.exe /r install \KVP\wvmic.inf vmbus\{242ff919-07db-4180-9c2e-b86cb68c8c55}”
CreateFakeService “TermService”, “Remote Desktop Service”, “FakeService.exe”
GetObject(“winmgmts:root\cimv2”).Get(“Win32_Service.Name=’vmickvpexchange'”).StartService()
oUtility.SafeSleep 10000
LoadVariablesFromHyperV

    End if

    ‘ Write back an unique number to the host to let them know that the variables have been loaded.
oUtility.RegWrite “HKLM\SOFTWARE\Microsoft\Virtual Machine\Auto\HydrationGuestStatus”,”eb471002-58aa-473a-850f-7b626613055f”

    Userexit=success

end function

‘ ———————————————————

Function CreateFakeService (sName,sDisplayName,sPathName )

    Dim objService
Dim objInParam

    ‘ Obtain the definition of the Win32_Service class.
Set objService = GetObject(“winmgmts:root\cimv2”).Get(“Win32_Service”)

    ‘ Obtain an InParameters object specific to the Win32_Service.Create method.
Set objInParam = objService.Methods_(“Create”).inParameters.SpawnInstance_()

    ‘ Add the input parameters.
objInParam.Properties_.item(“Name”) = sName
objInParam.Properties_.item(“DisplayName”) = sDisplayName
objInParam.Properties_.item(“PathName”) = sPathName
objInParam.Properties_.item(“ServiceType”) = 16
objInParam.Properties_.item(“ErrorControl”) = 0
objInParam.Properties_.item(“StartMode”) = “Manual”
objInParam.Properties_.item(“DesktopInteract”) = False

    ‘ Execute the method and obtain the return status.
CreateFakeService = objService.ExecMethod_(“Create”, objInParam).ReturnValue

End function

Function LoadVariablesFromHyperV

    Dim objReg
Dim aSubValues
Dim aValues
Dim SubVal

    oLogging.CreateEntry “Has MDT Environment Variables in Integration Components.”, LogTypeInfo
Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv”)
objReg.EnumValues &H80000002, “SOFTWARE\Microsoft\Virtual Machine\External”, aSubValues, aValues

    If isArray(aSubValues) then
For Each SubVal in aSubValues
oLogging.CreateEntry “Found Key: [” & SubVal & “]”, LogTypeInfo
oEnvironment.Item(SubVal) = oUtility.RegRead(“HKLM\SOFTWARE\Microsoft\Virtual Machine\External\” & SubVal)
Next
End if

End Function


ReadKVPData.vbs


‘//—————————————————————————-
‘// Version: 1.0 – Jan 04, 2013 – Mikael Nystrom
‘// Twitter @mikael_nystrom
‘// Blog
http://deploymentbunny.com
‘// This script is provided “AS IS” with no warranties, confers no rights and
‘// is not supported by the author
‘//—————————————————————————-
‘ //
‘ // Usage:     Modify CustomSettings.ini similar to this:
‘ //              [Settings]
‘ //              Priority=SetAlias, Default
‘ //              Properties=VMNameAlias
‘ //
‘ //              [SetAlias]
‘ //              VMNameAlias=#SetVMNameAlias()#
‘ // ***** End Header *****

Function UserExit(sType, sWhen, sDetail, bSkip)

    oLogging.CreateEntry “UserExit: started: ” & sType & ” ” & sWhen & ” ” & sDetail, LogTypeInfo
UserExit = Success

End Function

Function SetVMNameAlias()
oLogging.CreateEntry “UserExit: Running function SetVMNameAlias “, LogTypeInfo
SetVMNameAlias = “”
SetVMNameAlias = oShell.RegRead(“HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\VirtualMachineName”)
oLogging.CreateEntry “UserExit: SetVMNameAlias has been set to ” & SetVMNameAlias, LogTypeInfo
oLogging.CreateEntry “UserExit: Departing…”, LogTypeInfo
End Function


ImageFactoryV2.psm1


<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
.INPUTS
Inputs to this cmdlet (if any)
.OUTPUTS
Output from this cmdlet (if any)
.NOTES
General notes
.COMPONENT
The component this cmdlet belongs to
.ROLE
The role this cmdlet belongs to
.FUNCTIONALITY
The functionality that best describes this cmdlet
#>
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
# Read Settings from XML
[xml]$Global:Settings = Get-Content .\ImageFactoryV2.xml
$Global:DeploymentShare = $Global:Settings.Settings.DeploymentShare
$Global:StartUpRAM = 1024*1024*1024*$Global:Settings.Settings.StartUpRAM
$Global:VHDSize = 1024*1024*1024*$Global:Settings.Settings.VHDSize
$Global:SWitchName = $Global:Settings.Settings.HyperVHostNetwork
$Global:VMLocation = $Global:Settings.Settings.HyperVStorage
$Global:HyperVISOFolder = $Global:Settings.Settings.HyperVISOFolder
$Global:TaskSequenceFolder = $Global:Settings.Settings.TaskSequenceFolder
$Global:VLANID = $Global:Settings.Settings.VLANID

function New-AutoGenRefImages{
Process
{

    #Connect to MDT:
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction Stop
Remove-PSDrive MDT -ErrorAction SilentlyContinue
$Null = New-PSDrive -Name MDT -PSProvider MDTProvider -Root $Global:DeploymentShare -Force
$MDTSettings = Get-ItemProperty MDT:
$ISO = $MDTSettings.’Boot.x86.LiteTouchISOName’

    #Check if ISO exists
$ISOFileExist = Test-Path “$($Global:DeploymentShare)\Boot\$($ISO)”  -ErrorAction SilentlyContinue
If($ISOFileExist -like ‘False’){
Write-Host “Unable to find ISO, exit”
BREAK
}

    #Create Folders
$Null = New-Item -Path $HyperVISOFolder -ItemType Directory -Force -ErrorAction SilentlyContinue

    #Copy the BootImage from MDTServer to Hyper-VHost
Copy-Item “$($Global:DeploymentShare)\Boot\$($ISO)” $Global:HyperVISOFolder\ -Container -Force -ErrorAction Stop

    #Check if ISO exists
$ISOFileExist = Test-Path ($Global:HyperVISOFolder + “\” + $ISO) -ErrorAction Stop
If($ISOFileExist -like ‘False’){
Write-Host “Unable to find ISO, exit”
BREAK
}

    #Check if VMSwitch on host exists
$VMSwitchExist = Get-VMSwitch -Name $Global:SWitchName -ErrorAction SilentlyContinue
If($VMSwitchExist.Name -ne $Global:SWitchName){
Write-Host “Unable to find VMSwitch, exit”
BREAK
}

    #Create the VMs
$RefTS = Get-ChildItem $Global:TaskSequenceFolder -Recurse
Foreach($TS in $RefTS){

        #Set VMName to ID
$VMName = $TS.ID

        #Check if VM exists
$VMexist = Get-VM -Name $VMName -ErrorAction SilentlyContinue
If($VMexist.Name -like $VMName){
Write-Host “VM already exist, exit”
BREAK
}

        $VM = New-VM –Name $VMname –MemoryStartupBytes $Global:StartUpRAM -SwitchName $Global:SWitchName -NewVHDPath “$Global:VMLocation\$VMName\Virtual Hard Disks\$VMName.vhdx” -NewVHDSizeBytes $Global:VHDSize -Path $Global:VMLocation
Add-VMDvdDrive -VM $VM -Path ($Global:HyperVISOFolder + “\” + $ISO)

        #Set
Get-VM -Name $VMName | Set-VMProcessor -CompatibilityForMigrationEnabled $True
Get-VM -Name $VMName | Set-VMProcessor -Count 2
If($Global:VLANID -notlike “0”){
Get-VM -Name $VMName | Get-VMNetworkAdapter | Set-VMNetworkAdapterVlan -Access -VlanId $VLANID
}
}
Foreach($TS in $RefTS){
#Set VMName to ID
$VMName = $TS.ID
$VM = Get-VM -Name $VMName
$VM | Start-VM
Start-Sleep “10”
while($VM.State -like “Running”){
Write-Output “Waiting for $VMName to finish.”
Start-Sleep “120”}
Write-Output “$VMName is done, checking for more”
}
}
}
function Remove-AutoGenRefImages{
Process
{

    #Connect to MDT:
$Null = Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction SilentlyContinue
Remove-PSDrive MDT -ErrorAction SilentlyContinue
$Null = New-PSDrive -Name MDT -PSProvider MDTProvider -Root $Global:DeploymentShare -Force
$MDTSettings = Get-ItemProperty MDT:
$ISO = $MDTSettings.’Boot.x86.LiteTouchISOName’

        #Remove the VMs
$RefTS = Get-ChildItem $Global:TaskSequenceFolder -Recurse
Foreach($TS in $RefTS){

            #Set VMName to ID
$VMName = $TS.ID

            #Check if VM exists
$VMexist = Get-VM -Name $VMName -ErrorAction SilentlyContinue
If($VMexist.Name -like $VMName){
Write-Host “Removing $VMName”
$VMToRemove = Get-VM -Name $VMName
$FolderPath = $VMToRemove.path
if($VMToRemove.state -like “Running”){Stop-VM $VMToRemove -Force}
$VMToRemove | Remove-VM -Force
$FolderPath | Remove-Item -Force -Recurse
}
}
}
}
function New-RefImage{
[CmdletBinding()]
[OutputType([int])]
Param
(
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0)]
[String]
$TaskSequenceID
)

Process
{

    #Connect to MDT:
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction Stop
Remove-PSDrive MDT -ErrorAction SilentlyContinue
$Null = New-PSDrive -Name MDT -PSProvider MDTProvider -Root $Global:DeploymentShare -Force
$MDTSettings = Get-ItemProperty MDT:
$ISO = $MDTSettings.’Boot.x86.LiteTouchISOName’

    #Check if ISO exists
$ISOFileExist = Test-Path “$($Global:DeploymentShare)\Boot\$($ISO)”  -ErrorAction SilentlyContinue
If($ISOFileExist -like ‘False’){
Write-Host “Unable to find ISO, exit”
BREAK
}

    #Create Folders
$null = New-Item -Path $HyperVISOFolder -ItemType Directory -Force -ErrorAction SilentlyContinue

    #Copy the BootImage from MDTServer to Hyper-VHost
Copy-Item “$($Global:DeploymentShare)\Boot\$($ISO)” $Global:HyperVISOFolder\ -Container -Force -ErrorAction Stop

    #Check if ISO exists
$ISOFileExist = Test-Path ($Global:HyperVISOFolder + “\” + $ISO) -ErrorAction Stop
If($ISOFileExist -like ‘False’){
Write-Host “Unable to find ISO, exit”
BREAK
}

    #Check if VMSwitch on host exists
$VMSwitchExist = Get-VMSwitch -Name $Global:SWitchName -ErrorAction SilentlyContinue
If($VMSwitchExist.Name -ne $Global:SWitchName){
Write-Host “Unable to find VMSwitch, exit”
BREAK
}

    #Check if VM exists
$VMexist = Get-VM -Name $VMName -ErrorAction SilentlyContinue
If($VMexist.Name -like $VMName){
Write-Host “VM already exist, exit”
BREAK
}

    $VM = New-VM –Name $TaskSequenceID –MemoryStartupBytes $Global:StartUpRAM -SwitchName $Global:SWitchName -NewVHDPath “$Global:VMLocation\$TaskSequenceID\Virtual Hard Disks\$TaskSequenceID.vhdx” -NewVHDSizeBytes $Global:VHDSize -Path $Global:VMLocation
Add-VMDvdDrive -VM $VM -Path ($Global:HyperVISOFolder + “\” + $ISO)

    #Set
Get-VM -Name $TaskSequenceID | Set-VMProcessor -CompatibilityForMigrationEnabled $True -VM $VM

    #Set
Get-VM -Name $TaskSequenceID | Set-VMProcessor -Count 2

    #Set
If($VLANID -notlike “0”){
Get-VM -Name $TaskSequenceID | Get-VMNetworkAdapter | Set-VMNetworkAdapterVlan -Access -VlanId $VLANID
}

    }

}
function Remove-RefImage{
[CmdletBinding()]
[OutputType([int])]
Param
(
[Parameter(Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
Position=0)]
[String]
$VMName
)
Process
{

    #Check if VM exists
$VMexist = Get-VM -Name $VMName -ErrorAction SilentlyContinue
If($VMexist.Name -like $VMName){
Write-Host “Removing $VMName”
$VMToRemove = Get-VM -Name $VMName
$FolderPath = $VMToRemove.path
if($VMToRemove.state -like “Running”){Stop-VM $VMToRemove -Force}
$VMToRemove | Remove-VM -Force
$FolderPath | Remove-Item -Force -Recurse
}
}
}
function Get-RefTaskSequence{
Process
{

    #Connect to MDT:
Add-PSSnapIn Microsoft.BDD.PSSnapIn -ErrorAction Stop
Remove-PSDrive MDT -ErrorAction SilentlyContinue
$Null = New-PSDrive -Name MDT -PSProvider MDTProvider -Root $Global:DeploymentShare -Force
$MDTSettings = Get-ItemProperty MDT:
$ISO = $MDTSettings.’Boot.x86.LiteTouchISOName’

        #Get TS
$RefTS = Get-ChildItem $Global:TaskSequenceFolder -Recurse
Foreach($TS in $RefTS){
New-Object PSObject -Property @{
TaskSequenceID = $TS.ID
Name = $TS.Name
Comments = $TS.Comments
Version = $TS.Version
Enabled = $TS.enable
LastModified = $TS.LastModifiedTime
}
}
}
}

Export-ModuleMember -function *


/mike

Posted in Deployment, MDT, System Center 2012, System Center 2012 R2 | Tagged: , , | 73 Comments »

Nice to Know: Upgrade Sequencing for System Center 2012 R2

Posted by Mikael Nystrom on October 22, 2013

Microsoft has just released information on how to upgrade the System Center 2012 stack. Now BEFORE you start, you need to figure out where to start and what’s to be done in other system center products at the same time. In many cases you will not be able to upgrade the entire stack at the same time, there for all interactions between needs to be taken seriously. As an example, if you do have Orchestrator integration, you need to upgrade the OR server first, but it does not mean all the OIPS should be upgraded, the should of course be upgraded when the corresponding SC2012R2 system gets updated, so there is a lot to think about…

The link is here http://technet.microsoft.com/en-us/library/dn521010.aspx

Some highlights:

Orchestrator: http://technet.microsoft.com/en-us/library/jj628201.aspx

  • If Orchestrator is part of your environment, then Orchestrator will be the first component that you upgrade.

Service Manager: http://technet.microsoft.com/en-us/library/jj628207.aspx

Data Protection Manager: http://technet.microsoft.com/en-us/library/jj628208.aspx

  • There are some new features that are available with Data Protection Manager (DPM) that are only available when using Windows Server 2012.

Operations Manager: http://technet.microsoft.com/en-us/library/jj628193.aspx

After you upgrade Operations Manager, you might have to install the Operations Manager console on some of the down-level components.

  • There are some new features that are available with Operations Manager that are only available when using Windows Server 2012.

Configuration Manager: http://technet.microsoft.com/en-us/library/jj628195.aspx

Virtual Machine Manager and App Controller: http://technet.microsoft.com/en-us/library/jj628212.aspx

Posted in Deployment, System Center 2012 R2 | Leave a Comment »