Hello Friends,
Is there a way I can know which task sequence is used to deploy a particular machine?
Yes, we can update the registry key with the Task Sequence info like, which Task Sequence is used to deploy the OS on a particular machine?
from Which DP the contents are downloaded? Is the machine built with Boot media or it is PXE boot?
Is this a machine desktop or laptop? what is the machine type, machine model?
Also, we can get when the machine is imaged(date and time when the Task Sequence is deployed).
First, we have to gather all the information which we want to update in the registry.
let's take the example of DP's name...
How do we know from which DP the contents are getting downloaded? from where I can get this information? is it a simple variable which I can use to update the registry? No.
While running the Task Sequence all the variable data is stored in a .dat file and we can fetch that using "New-Object -ComObject 'Microsoft.SMS.TSEnvironment"
The value against "("_SMSTSLastContentDownloadLocation")" will be found in the above string.
then we can use the same in the registry to update the info like "Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name DPInformation -Value $DPName -Force -Confirm:$false" Create $OSDBrandingName and $DPName variable before update the registry path.
In the $DPName variable use $DPvalue.Substring($startIndex, $endIndex-$startIndex) value from Task Sequence varible
for other veriable like whethermachine is desktop or laptop, you can get this infor from the Task Sequence variable("New-Object -ComObject 'Microsoft.SMS.TSEnvironment") only.
OS version and build number I have fetched from registry only. like in Windows Operating System it is stored in the registry path-"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\currentBuild" or "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\releasedID".
Also, you can add your custom variables also and update the registry to get more info about OSD.
In the below PowerShell script I have covered most of the above things. let's create an SCCM package using the below PowerShell script and distribute it on the desired DPs.
Add this package in the Task Sequence anywhere post WinPE stage or SCCM client is installed (the first reboot is completed).
don't forget to bypass the PowerShell in Task Sequence and share the feedback😀👍👍
<#
.SYNOPSIS
Update Registry with the info on which Task Sequence
was used to deploy a particular machine.
.DESCRIPTION
This script will update the Task sequence info, DP info, and Other basic OS-related useful Info into the Registry key.
.NOTES
=============================================================================================================================================
Created with: Windows PowerShell ISE
Created on: Thursday,
June 25, 2020, 2:18:36 PM
Created by: Dashrath Chate
Organization: Organization Name
=============================================================================================================================================
#>
$TSEnv = New-Object -ComObject 'Microsoft.SMS.TSEnvironment'
$DPvalue = $TSEnv.Value("_SMSTSLastContentDownloadLocation")
$startIndex = $DPValue.IndexOf('://') + 3
$endIndex = $DPValue.IndexOf('/', $startIndex)
$DPName = $DPvalue.Substring($startIndex, $endIndex-$startIndex)
$TSEnv.Value('DPName') = $DPName
$Persona = $TSEnv.Value("OSDDepartment")
$TSMediaType = $TSEnv.Value("_SMSTSMediaType")
$TSName = $TSEnv.Value("_SMSTSPackageName")
$OSDImageType = $TSEnv.Value("OSDImageType")
$ImageServer = $TSEnv.Value("BootMedia")
$OSDIntern = $TSEnv.Value("OSDIntern")
$OSDBrandingName = "YourCompanyNme" #Change
this value as per your company name so that registry key can be created
accordingly.
If ($TSEnv.Value("IsLaptop") -eq "True")
{
$AssetType = "LAPTOP"
}
Else
{
$AssetType = "DESKTOP"
}
$ImageDate =Get-Date
$OSVersionNumber=(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\').currentBuild
$Windows_Version=(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\').releaseId
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name MachineType -Value $Persona -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name MachineModel -Value $AssetType -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name ImageDate -Value $ImageDate -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name ImageServer -Value $TSMediaType -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name ImageType -Value $OSDImageType -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name Intern -Value $OSDIntern -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name 'Task
Sequence' -Value $TSName -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name 'OS
Build' -Value $OSVersionNumber -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name Version -Value $Windows_Version -Force -Confirm:$false
Set-ItemProperty -Path Registry::HKLM:\SOFTWARE\$OSDBrandingName -Name DPInformation -Value $DPName -Force -Confirm:$false
No comments:
Post a Comment
Leave your valuable words here for improve better.