Loading

Diskpart to the rescue

In my work, I recently heard that more often new devices (desktop’s/laptop’s) fails in the beginning of the OSD (OS deploy) because of something is wrong with the partitions on the hard drive. The Boot-image can’t download policys or files to the disk, so it fails.

Often the IT-person needs to boot the device and re-partition the disk, and after that start the OSD again, and it will work.

I have not done some examination on why it fails. The OEM’s OS works on the device/disk.

But I have a workaround, or it’s not mine workaround. I did find it on the Internet for a few years ago, so I don’t remember whos to credit (I’m sorry).

But this is the workaround I have.

Begin by creating a txt-file with the content of commands for diskpart we will be using later (this is for UEFI-disks).

sel disk 0
clean
convert gpt
cre par efi size=200
assign letter=s
format quick fs=FAT32
cre par msr size=128
cre par pri
assign letter=c
format quick fs=NTFS
exit

Save the file (I have named my file uefi_disk.txt ), and put it on your SCCM Package-share.
Then you will need to create a Package in your SCCM-console, where you will point out the source files (where you saved your new .txt-file).

You don’t need to create a program, just select “Do not create a program” and click next, and just go on and finish the wizard.

Here is two ways to use this.

The first one, if you boot your PC’s from a boot-media (CD/USB), you can create a new boot-media and put in a prestart command to run diskpart. So go one and create a new Task Sequence Media if you choose this way.

Mark Boot media, and Next

Continue the wizard, entering your “SCCM-info” till you come to Customize the task sequence media.

Here you will need to tick the Enable prestart command checkbox, and also enter Command line:
cmd.exe /c diskpart /s uefi_disk.txt <– or the name you gave your .txt-file
You must also select the Diskpart package you created earlier, and point out your Distribution point.

After that, finish the wizard, and you are now ready to boot using your new boot-media.


The other one is to put this in your boot-image (if you PXE-boot your devices, choose this). Using this way the prestart command will always run (when using TS using this boot-image), and you don’t need to create a new boot-image with this prestart command.

Go to your Boot-image in the SCCM-console, and right-click it and choose Properties.
Go to the Customization tab, and tick the Enable prestart command checkbox, and also enter Command line:
cmd.exe /c diskpart /s uefi_disk.txt <– or the name you gave your .txt-file
Klick Ok, to save and re-distribute your boot-image, and after that your done.


When you are here, click Next

And diskpart will run

After diskpart is finished, you can choose your TS, and continue your installation

Paus i jobbhelgen

jobbhelgHelgjobb står på tapeten denna helg.
Började gårdagen med att ominstallera 15 RDS:er. På dagens agenda står det patchning av servrar för min del, men just nu väntar jag på att kollegorna ska bli klara med brandväggsjobb så att nätverket åter blir tillgängligt och jag kan fortsätta patchningen.

Under tiden så tar jag och bläddrar lite i Deployment Fundamentals, Vol. 6: Deploying Windows 10 Using Microsoft Deployment Toolkit som damp ner i brevlådan igår. Det får gärna ta ett tag med brandväggsjobbet känner jag 🙂 .

Krasslig idag, beställde en bok

dfv6Förkyld, utslagen allmänt gnäll. Men en bok köptes in, Deployment Fundamentals, Vol. 6: Deploying Windows 10 Using Microsoft Deployment Toolkit.
Hoppas på snabb leverans. På något sjukt sätt så tycker jag sådant här är kul, samt att jag råkar kunna använda det i jobbet…

Hoppas nu bara att jag lyckas skrapa ihop hårdvara för att kunna få till lämplig labbmiljö.

 

Uppdatera Configmgr Content, där det behövs

Återigen, Rikard Rönnkvist spar mig massor av tid med sina PowerShell-script, tack!

PARAM (
    $sccmServer = "configmgr.snowland.se",
    $sccmSiteCode = "ABC",
    $failStates = "2, 3, 5, 6", # Retrying and Failed (Both Install and Removal)
    $packageTypes = "0, 3, 4, 8, 257, 258" # Not checking 5 (SUP) due to automatic deployments
)
 
Write-Host "Searching for failed content distributions"
ForEach ($FailedDist in (Get-WmiObject -ComputerName $sccmServer -Namespace "ROOT\SMS\Site_$($sccmSiteCode)" -Query "SELECT * FROM SMS_PackageStatusDistPointsSummarizer WHERE State IN ($($failStates)) AND PackageType IN ($($packageTypes))" | Sort-Object PackageID)) {
     
    # Figure out servername from NalPath
    $failedServer = $FailedDist.ServerNALPath.Substring($FailedDist.ServerNALPath.LastIndexOf("]")+3).Trim("\")
 
    # Get the distribution points that content wouldn't distribute to
    ForEach ($FailedDPDist in (Get-WmiObject -ComputerName $sccmServer -Namespace "ROOT\SMS\Site_$($sccmSiteCode)" -Query "SELECT * FROM SMS_DistributionPoint WHERE SiteCode='$($FailedDist.SiteCode)' AND PackageID='$($FailedDist.PackageID)' AND ServerNALPath LIKE '%$($failedServer)%'") ) {
        # Refresh content on the selected DP
        Write-Host "Refreshing $($FailedDPDist.PackageID), type $($FailedDist.PackageType) in state $($FailedDist.State) on $($failedServer)"
        $FailedDPDist.RefreshNow = $true
        $FailedDPDist.Put() | Out-Null
    }
}
 
Write-Host "Done!"

Tack till Rikard Rönnkvist, källa: SnowLand

Exportera / Importera Boot-image drivrutiner till ny Boot-image

Återigen, ett mycket bra PowerShell-script som besparar massa tid.

Function Export-BootImageDrivers {
    PARAM (
        [String] $ImageId,
        [String] $ExportXml
    )
  
    $drivers = @{}
    (Get-CMBootImage -Id $ImageId).ReferencedDrivers | ForEach-Object {
        Write-Verbose "Found driver ID - $($_.Id)"
 
        $drivers.Add($_.Id, $_.SourcePath)
    }
 
    $drivers | Export-Clixml -Path $ExportXml
}
 
Function Import-BootImageDrivers {
    PARAM (
        [String] $ImageId,
        [String] $ExportXml
    )
 
    $BootImage = Get-CMBootImage -Id $ImageId
    $drivers = Import-Clixml -Path $ExportXml
    $drivers.GetEnumerator() | ForEach-Object {
        Write-Verbose "Adding driver ID - $($_.Name)"
        Set-CMDriver -Id $_.Name -AddBootImagePackage $BootImage -UpdateDistributionPointsforBootImagePackage $false -Force
    }
}

Exportera först drivrutinerna

Export-BootImageDrivers -ImageId “ABC00123” -ExportXml “D:\Script\PS\drivers.xml”

Uppgradera Boot-imagen

Sedan importera drivrutinerna

Import-BootImageDrivers -ImageId “ABC00345” -ExportXml “D:\Script\PS\drivers.xml”

Tack till Rikard Rönnkvist, källa: SnowLand

Kopiera drivrutiner från en boot-image till en annan

Lifesaver. Eller med andra ord, en grym tidsbesparare.

Function Copy-BootImageDrivers {
    PARAM (
        $from, $to
    )
 
    $boot = Get-CMBootImage -ID $to
 
    (Get-CMBootImage -Id $from).ReferencedDrivers | ForEach-Object {
        Write-Verbose "Copying $($_.Id) to $($to)"
        Set-CMDriver -Id $_.Id -AddBootImagePackage $boot -UpdateDistributionPointsforBootImagePackage $false
    }
 
}
 
#Example use
Copy-BootImageDrivers -from "ABC00123" -to "ABC00456"

Tack till Rikard Rönnkvist, källa SnowLand