Friday, June 16, 2017

How to Pre-Stage in SCCM

What is pre-stage?

The idea behind pre-stage is simple, you take all of your OSD task sequence content and put it onto the hard drive of the PC. You then boot to the hard drive and that becomes your boot media. Then run a task sequence and any content that is on the hard drive will be used locally any content that is not on the drive will be pulled from your SCCM infrastructure. OEMs can use pre-stage media in the factory to put your task sequence content on the drive so when you get your equipment it's ready to go.

Here's how to test it and do it without an OEM for sites with slow WAN links

Step 1: Create a task sequence with all of your apps and driver packages. I won't detail this here because if you're at the pre-stage step you probably already have this.

Step 2: Create a pre-stage media (wim) of the task sequence. Follow the Microsoft documentation: https://technet.microsoft.com/en-us/library/gg294170.aspx

2.1 Import the WIM into system center and distribute it to at least one DP.

Step 3: Create a pre-stage task sequence. This will test pre-stage before you send it to your OEM or sites with slow connections.

3.1 download the files here and make a package out of them.

3.2 Create the step below referencing the package you created from the files.



3.3 Apply the Data WIM you created earlier from task sequence with all the driver and apps.

3.4 Use the BCD edit script to make the hard drive bootable and work with secure boot.


3.5 Shutdown the PC


Step 4: Create standalone media for the pre-stage task sequence: https://technet.microsoft.com/en-us/library/bb632784.aspx. Remember this has the data WIM in it with Windows as well as all of your drivers and apps.

4.1 Using 7-zip extract the ISO to a USB flash drive


Step 5: Boot the PC with your flash drive and run the pre-stage task sequence. When the task sequence finishes it will shut down the PC. 

Step 6: Remove the flash drive and boot the PC to the hard drive. If configured correctly the PC will now search for all of the available task sequences to it and start using the content on the drive as necessary. 


Thursday, March 30, 2017

Use PowerShell to Create a Switch and VM


This PowerShell script copies an ISO to a local directory, creates a Switch bound to the ethernet adapter then creates a virtual machine and attaches it to the switch.

<# Create Hyper-V folder and copy ISO #>
$VMLOC = "C:\Users\Public\Documents\Hyper-V"
Write-Host "Copying ISO. Please Wait"
Copy-Item .\CMBOOT.iso $VMLOC -Force > $nul
Write-Host ""
Write-Host "ISO Copied"

<# Create Hyper-V Switch #>
Import-Module Hyper-V
$ethernet = Get-NetAdapter -Name ethernet
New-VMSwitch -Name External_Switch -NetAdapterName $ethernet.Name -AllowManagementOS $true -Notes ‘Parent OS, VMs, LAN’

<# Create Hyper-V Machine and connect to it #>
$VMName = "Windows_7_VM"
$RAM = 4GB
$VHDSize = 120GB
$VMSwitch = "External_Switch"
$W7ISO = "$VMLOC\CMBOOT.iso"
New-VM -Name $VMName -Path $VMLOC -MemoryStartupBytes $RAM -NewVHDPath "$VMLOC\$VMName.vhdx" -NewVHDSizeBytes $VHDSize -Switchname $VMSwitch
Set-VMDvdDrive -VMName $VMName -Path $W7ISO

Add every member of the Users group to the Hyper-V Administrators group.


I recently had a challenge to make Hyper-V available to everyone on a PC and it had to work in other languages. So net localgroup is out since you have to use the SID of the groups. Here is the PowerShell script I used for that.






#Gets all of the local groups
$GetGroups = Get-WmiObject -Query "select * from win32_group where Domain='$env:computername'"

#Selects the Hyper-V Administrators group from the array using the well known SID
$hyperVgroup= $GetGroups | Where-Object {$_.SID -eq 'S-1-5-32-578'}
$HVgroupName= $hyperVgroup.Name

#Selects the Users group from the array using the well known SID
$UserGroup = $GetGroups | Where-Object {$_.SID -eq 'S-1-5-32-545'}
$Usergroupname = $UserGroup.Name

#Gets the members of the Users group.
$Group = [ADSI]"WinNT://$env:Computername/$usergroupname,group"
if ($Group.Path)
            {
                $Members = @($Group.psbase.Invoke("Members"))
                [Array]$MemberNames = $Members |
                    ForEach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)} }

<#Takes the members from the Users group and puts them into the Hyper-V Admin group.
This will result in errors since some of the accounts are not "NT Authority" #>
foreach($member in $MemberNames){
([adsi]”WinNT://./$HVgroupName,group”).Add(“WinNT://NT Authority/$member,user”) > $null
}