mirror of
https://github.com/freedbygrace/Set-OSDInformation.git
synced 2026-08-31 04:38:36 +00:00
Add files via upload
This commit is contained in:
+44
-75
@@ -310,9 +310,7 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Always define a variable that details when the system was deployed. The timestamp is according to when this script calculated the current date/time which is converted to the destination time zone ID, then to UTC, then converted to the WMI format and stored.
|
#Always define a variable that details when the system was deployed. The timestamp is according to when this script calculated the current date/time which is converted to the destination time zone ID, then to UTC, then converted to the WMI format and stored.
|
||||||
$ConvertedSystemTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId((Get-Date), ($DestinationTimeZoneID))
|
$DefaultOSDVariables += (Set-Variable -Name "DeploymentTimestamp" -Value ((Get-Process -ID $PID).StartTime) -PassThru -Force -Verbose)
|
||||||
$ConvertedSystemTimeUTC = $ConvertedSystemTime.ToUniversalTime()
|
|
||||||
$DefaultOSDVariables += (Set-Variable -Name "DeploymentTimestamp" -Value ([System.Management.ManagementDateTimeConverter]::ToDmtfDateTime($ConvertedSystemTimeUTC)) -PassThru -Force -Verbose)
|
|
||||||
|
|
||||||
#Always define a variable that details which product deployed the task sequence
|
#Always define a variable that details which product deployed the task sequence
|
||||||
$DefaultOSDVariables += (Set-Variable -Name "DeploymentProduct" -Value ($DeploymentProduct) -PassThru -Force -Verbose)
|
$DefaultOSDVariables += (Set-Variable -Name "DeploymentProduct" -Value ($DeploymentProduct) -PassThru -Force -Verbose)
|
||||||
@@ -323,6 +321,8 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
#Create a variable for each default variable specified
|
#Create a variable for each default variable specified
|
||||||
ForEach ($DefaultOSDVariable In $DefaultOSDVariableListSorted)
|
ForEach ($DefaultOSDVariable In $DefaultOSDVariableListSorted)
|
||||||
{
|
{
|
||||||
|
$DefaultOSDVariableValueConverted = $Null
|
||||||
|
|
||||||
#Remove all instances of invalid character(s) from the variable name(s) using a regular expression. This is to avoid potential WMI property creation error(s).
|
#Remove all instances of invalid character(s) from the variable name(s) using a regular expression. This is to avoid potential WMI property creation error(s).
|
||||||
$DefaultOSDVariableName = $DefaultOSDVariable -ireplace "(_)|(\s)|(\.)", ""
|
$DefaultOSDVariableName = $DefaultOSDVariable -ireplace "(_)|(\s)|(\.)", ""
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
$DefaultOSDVariableValueAsDateTime = Get-Date -Date "$($DefaultOSDVariableValue)"
|
$DefaultOSDVariableValueAsDateTime = Get-Date -Date "$($DefaultOSDVariableValue)"
|
||||||
$ConvertedDefaultOSDVariableDateTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId(($DefaultOSDVariableValueAsDateTime), ($DestinationTimeZoneID))
|
$ConvertedDefaultOSDVariableDateTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId(($DefaultOSDVariableValueAsDateTime), ($DestinationTimeZoneID))
|
||||||
$ConvertedDefaultOSDVariableDateTimeUTC = $ConvertedDefaultOSDVariableDateTime.ToUniversalTime()
|
$ConvertedDefaultOSDVariableDateTimeUTC = $ConvertedDefaultOSDVariableDateTime.ToUniversalTime()
|
||||||
$DefaultOSDVariableValueConverted = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime($ConvertedDefaultOSDVariableDateTimeUTC)
|
$DefaultOSDVariableValueConverted = $ConvertedDefaultOSDVariableDateTimeUTC
|
||||||
}
|
}
|
||||||
|
|
||||||
{($DefaultOSDVariableValue -imatch "^True$|^False$")}
|
{($DefaultOSDVariableValue -imatch "^True$|^False$")}
|
||||||
@@ -366,7 +366,7 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
|
|
||||||
$DefaultOSDVariableValueConverted = "$($TaskSequenceXMLDefinition_ImagePackageID[0].Node.InnerText)"
|
$DefaultOSDVariableValueConverted = "$($TaskSequenceXMLDefinition_ImagePackageID[0].Node.InnerText)"
|
||||||
|
|
||||||
If ($DefaultOSDVariableValueConverted)
|
If ([String]::IsNullOrEmpty($DefaultOSDVariableValueConverted) -eq $False)
|
||||||
{
|
{
|
||||||
$DefaultOSDVariables += (Set-Variable -Name "ImagePackageID" -Value ($DefaultOSDVariableValueConverted) -PassThru -Force -Verbose)
|
$DefaultOSDVariables += (Set-Variable -Name "ImagePackageID" -Value ($DefaultOSDVariableValueConverted) -PassThru -Force -Verbose)
|
||||||
}
|
}
|
||||||
@@ -396,6 +396,8 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
#Create all the variable(s) that will be written to the system in the desired storage location
|
#Create all the variable(s) that will be written to the system in the desired storage location
|
||||||
ForEach ($CustomOSDVariable In $CustomOSDVariableListSorted)
|
ForEach ($CustomOSDVariable In $CustomOSDVariableListSorted)
|
||||||
{
|
{
|
||||||
|
$CustomOSDVariableValueConverted = $Null
|
||||||
|
|
||||||
#Remove the attribute prefix from the variable name(s). This is for cleaner output purposes.
|
#Remove the attribute prefix from the variable name(s). This is for cleaner output purposes.
|
||||||
$CustomOSDVariableName = $CustomOSDVariable -ireplace "$($OSDVariablePrefix)", ""
|
$CustomOSDVariableName = $CustomOSDVariable -ireplace "$($OSDVariablePrefix)", ""
|
||||||
|
|
||||||
@@ -403,14 +405,14 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
$CustomOSDVariableValue = $TSEnvironment.Value($CustomOSDVariable)
|
$CustomOSDVariableValue = $TSEnvironment.Value($CustomOSDVariable)
|
||||||
|
|
||||||
#Attempt to format any custom variable(s) to their respective data types. This is for data consistency purposes.
|
#Attempt to format any custom variable(s) to their respective data types. This is for data consistency purposes.
|
||||||
Switch ($CustomOSDVariable)
|
Switch ($CustomOSDVariableName)
|
||||||
{
|
{
|
||||||
{($_ -imatch '.*Date.*|.*Timestamp.*|.*Start.*Time.*|.*End.*Time.*')}
|
{($_ -imatch '.*Date.*|.*Timestamp.*|.*Start.*Time.*|.*End.*Time.*')}
|
||||||
{
|
{
|
||||||
$CustomOSDVariableValueAsDateTime = Get-Date -Date "$($CustomOSDVariableValue)"
|
$CustomOSDVariableValueAsDateTime = Get-Date -Date "$($CustomOSDVariableValue)"
|
||||||
$ConvertedCustomOSDVariableDateTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId(($CustomOSDVariableValueAsDateTime), ($DestinationTimeZoneID))
|
$ConvertedCustomOSDVariableDateTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId(($CustomOSDVariableValueAsDateTime), ($DestinationTimeZoneID))
|
||||||
$ConvertedCustomOSDVariableDateTimeUTC = $ConvertedCustomOSDVariableDateTime.ToUniversalTime()
|
$ConvertedCustomOSDVariableDateTimeUTC = $ConvertedCustomOSDVariableDateTime.ToUniversalTime()
|
||||||
$CustomOSDVariableValueConverted = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime($ConvertedCustomOSDVariableDateTimeUTC)
|
$CustomOSDVariableValueConverted = $ConvertedCustomOSDVariableDateTimeUTC
|
||||||
}
|
}
|
||||||
|
|
||||||
{($CustomOSDVariableValue -imatch "^True$|^False$")}
|
{($CustomOSDVariableValue -imatch "^True$|^False$")}
|
||||||
@@ -445,7 +447,7 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
#Attempt to automatically create a timespan between the OSD Start Time and OSD End Time (This will only occur if these custom variables exist) (This data will allow you to track how long a task sequence deployment took for a device)
|
#Attempt to automatically create a timespan between the OSD Start Time and OSD End Time (This will only occur if these custom variables exist) (This data will allow you to track how long a task sequence deployment took for a device)
|
||||||
If (($CustomOSDVariables.Name -icontains "OSDStartTime") -and ($CustomOSDVariables.Name -icontains "OSDEndTime"))
|
If (($CustomOSDVariables.Name -icontains "OSDStartTime") -and ($CustomOSDVariables.Name -icontains "OSDEndTime"))
|
||||||
{
|
{
|
||||||
$OSDTimeSpan = New-TimeSpan -Start ([System.Management.ManagementDateTimeConverter]::ToDateTime($OSDStartTime)) -End ([System.Management.ManagementDateTimeConverter]::ToDateTime($OSDEndTime))
|
$OSDTimeSpan = New-TimeSpan -Start ($OSDStartTime) -End ($OSDEndTime)
|
||||||
|
|
||||||
$CustomOSDVariables += (Set-Variable -Name "OSDTotalSeconds" -Value ([System.Math]::Round($OSDTimeSpan.TotalSeconds, 2)) -PassThru -Force -Verbose)
|
$CustomOSDVariables += (Set-Variable -Name "OSDTotalSeconds" -Value ([System.Math]::Round($OSDTimeSpan.TotalSeconds, 2)) -PassThru -Force -Verbose)
|
||||||
$CustomOSDVariables += (Set-Variable -Name "OSDTotalMinutes" -Value ([System.Math]::Round($OSDTimeSpan.TotalMinutes, 2)) -PassThru -Force -Verbose)
|
$CustomOSDVariables += (Set-Variable -Name "OSDTotalMinutes" -Value ([System.Math]::Round($OSDTimeSpan.TotalMinutes, 2)) -PassThru -Force -Verbose)
|
||||||
@@ -461,8 +463,6 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
#If specified, write the OSD information to a new or existing registry key
|
#If specified, write the OSD information to a new or existing registry key
|
||||||
If ($Registry.IsPresent -eq $True)
|
If ($Registry.IsPresent -eq $True)
|
||||||
{
|
{
|
||||||
$CreatedRegistryObjects = @()
|
|
||||||
|
|
||||||
ForEach ($OSDVariable in $OSDVariables)
|
ForEach ($OSDVariable in $OSDVariables)
|
||||||
{
|
{
|
||||||
$OSDVariableName = "$($OSDVariable.Name)"
|
$OSDVariableName = "$($OSDVariable.Name)"
|
||||||
@@ -476,66 +476,18 @@ ForEach ($ModuleGroup In $ModuleGroups)
|
|||||||
$OSDVariableValue = ""
|
$OSDVariableValue = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
$CreatedRegistryObjects += (New-RegistryItem -Key "$($RegistryKeyPath)" -ValueName "$($OSDVariableName)" -Value ($OSDVariableValue) -ValueType 'String' -PassThru -Verbose)
|
New-RegistryItem -Key "$($RegistryKeyPath)" -ValueName "$($OSDVariableName)" -Value ($OSDVariableValue) -ValueType 'String' -Verbose
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#If specified, write the OSD information to a new WMI class. The class will be removed and recreated if it exists! A MOF file will be dynamically generated and compiled using MOFCOMP with auto recovery in the event of WMI repository rebuilds.
|
#region Dynamic MOF Creation
|
||||||
|
#If specified, write the OSD information to a new WMI class. The class will be removed and recreated if it exists! A MOF file will be dynamically generated and compiled using MOFCOMP with auto recovery in the event of WMI repository rebuilds. In other words, this custom WMI class will survive rebuilds of the WMI repository.
|
||||||
If ($WMI.IsPresent -eq $True)
|
If ($WMI.IsPresent -eq $True)
|
||||||
{
|
{
|
||||||
#region Dynamic MOF Creation
|
|
||||||
$MOFContents = $Null
|
|
||||||
|
|
||||||
[System.Text.StringBuilder]$MOFContents = [System.Text.StringBuilder]::New()
|
[System.Text.StringBuilder]$MOFContents = [System.Text.StringBuilder]::New()
|
||||||
|
|
||||||
[Void]$MOFContents.AppendLine()
|
[System.Text.StringBuilder]$WMIInstanceDefinition = [System.Text.StringBuilder]::New()
|
||||||
|
|
||||||
[String]$WMIRegistryProvider = @"
|
|
||||||
//==================================================================
|
|
||||||
// Register Registry property provider (shipped with WMI)
|
|
||||||
// Refer to WMI SDK documentation for use
|
|
||||||
//==================================================================
|
|
||||||
|
|
||||||
#pragma namespace(`"$("\\\\.\\$($Namespace.Replace('\', '\\'))")`")
|
|
||||||
|
|
||||||
// Registry instance provider
|
|
||||||
instance of __Win32Provider as `$InstProv
|
|
||||||
{
|
|
||||||
Name ="RegProv" ;
|
|
||||||
ClsID = "{fe9af5c0-d3b6-11ce-a5b6-00aa00680c3f}" ;
|
|
||||||
ImpersonationLevel = 1;
|
|
||||||
PerUserInitialization = "False";
|
|
||||||
};
|
|
||||||
|
|
||||||
instance of __InstanceProviderRegistration
|
|
||||||
{
|
|
||||||
Provider = `$InstProv;
|
|
||||||
SupportsPut = True;
|
|
||||||
SupportsGet = True;
|
|
||||||
SupportsDelete = False;
|
|
||||||
SupportsEnumeration = True;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Registry property provider
|
|
||||||
instance of __Win32Provider as `$PropProv
|
|
||||||
{
|
|
||||||
Name ="RegPropProv" ;
|
|
||||||
ClsID = "{72967901-68EC-11d0-B729-00AA0062CBB7}";
|
|
||||||
ImpersonationLevel = 1;
|
|
||||||
PerUserInitialization = "False";
|
|
||||||
};
|
|
||||||
|
|
||||||
instance of __PropertyProviderRegistration
|
|
||||||
{
|
|
||||||
Provider = `$PropProv;
|
|
||||||
SupportsPut = True;
|
|
||||||
SupportsGet = True;
|
|
||||||
};
|
|
||||||
"@
|
|
||||||
|
|
||||||
[Void]$MOFContents.Append($WMIRegistryProvider)
|
|
||||||
|
|
||||||
[Void]$MOFContents.AppendLine()
|
|
||||||
[Void]$MOFContents.AppendLine()
|
[Void]$MOFContents.AppendLine()
|
||||||
|
|
||||||
[String]$WMIClassDefinitionHeader = @"
|
[String]$WMIClassDefinitionHeader = @"
|
||||||
@@ -595,6 +547,11 @@ class $($Class)
|
|||||||
|
|
||||||
$WMIPropertyDefinition = "`t$($PropertyType) $($OSDVariableName);"
|
$WMIPropertyDefinition = "`t$($PropertyType) $($OSDVariableName);"
|
||||||
|
|
||||||
|
$WMIInstancePropertyName = "`t$($OSDVariableName);"
|
||||||
|
|
||||||
|
[Void]$WMIInstanceDefinition.Append($WMIInstancePropertyName)
|
||||||
|
[Void]$WMIInstanceDefinition.AppendLine()
|
||||||
|
|
||||||
[Void]$MOFContents.Append($WMIPropertyDefinition)
|
[Void]$MOFContents.Append($WMIPropertyDefinition)
|
||||||
[Void]$MOFContents.AppendLine()
|
[Void]$MOFContents.AppendLine()
|
||||||
}
|
}
|
||||||
@@ -617,21 +574,11 @@ instance of $($Class)
|
|||||||
[Void]$MOFContents.Append($WMIInstanceDefinitionHeader)
|
[Void]$MOFContents.Append($WMIInstanceDefinitionHeader)
|
||||||
[Void]$MOFContents.AppendLine()
|
[Void]$MOFContents.AppendLine()
|
||||||
|
|
||||||
ForEach ($CreatedRegistryObject In $CreatedRegistryObjects)
|
[Void]$MOFContents.Append($WMIInstanceDefinition.ToString())
|
||||||
{
|
|
||||||
$WMIInstancePropertyContext = "`t[PropertyContext(`"$($CreatedRegistryObject.KeyPath_WMIMOF)`"), Dynamic, Provider(`"RegPropProv`")]"
|
|
||||||
[Void]$MOFContents.Append($WMIInstancePropertyContext)
|
|
||||||
[Void]$MOFContents.AppendLine()
|
|
||||||
[Void]$MOFContents.Append("`t$($CreatedRegistryObject.ValueName);")
|
|
||||||
[Void]$MOFContents.AppendLine()
|
|
||||||
[Void]$MOFContents.AppendLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
[Void]$MOFContents.Append("};")
|
[Void]$MOFContents.Append("};")
|
||||||
|
|
||||||
[Void]$MOFContents.AppendLine()
|
[Void]$MOFContents.AppendLine()
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Export dynamically created MOF
|
#region Export dynamically created MOF
|
||||||
[System.IO.FileInfo]$MOFExportPath = "$([System.Environment]::SystemDirectory)\wbem\$($ScriptPath.BaseName).mof"
|
[System.IO.FileInfo]$MOFExportPath = "$([System.Environment]::SystemDirectory)\wbem\$($ScriptPath.BaseName).mof"
|
||||||
@@ -693,9 +640,31 @@ instance of $($Class)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Output -InputObject (Get-WMIObject -NameSpace "$($Namespace)" -Class "$($Class)")
|
#Show the WMI class BEFORE the properties get their values assigned
|
||||||
|
Write-Output -InputObject (Get-WMIObject -NameSpace ($Namespace) -Class ($Class))
|
||||||
|
|
||||||
|
#Retrieve the newly created WMI class and set the values of each property
|
||||||
|
$CIMInstance = Get-CIMInstance -Namespace ($Namespace) -ClassName ($Class)
|
||||||
|
|
||||||
|
$CIMInstanceProperties = $CIMInstance.CimInstanceProperties | Where-Object {($_.Name -iin ($OSDVariables.Name))}
|
||||||
|
|
||||||
|
ForEach ($CIMInstanceProperty In $CIMInstanceProperties)
|
||||||
|
{
|
||||||
|
$CIMInstancePropertyName = $CIMInstanceProperty.Name
|
||||||
|
|
||||||
|
$OSDVariableProperties = $OSDVariables | Where-Object {($_.Name -ieq $CIMInstancePropertyName)}
|
||||||
|
|
||||||
|
$LogMessage = "Attempting to assign the WMI property value for `"$($CIMInstancePropertyName)`". Please Wait... | [Namespace: $($Namespace)] - [Class: $($Class)]"
|
||||||
|
Write-Verbose -Message "$($LogMessage)" -Verbose
|
||||||
|
|
||||||
|
Set-CIMInstance -InputObject ($CIMInstance) -Property @{"$($CIMInstancePropertyName)" = ($OSDVariableProperties.Value)}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Show the WMI class AFTER the properties get their values assigned
|
||||||
|
Write-Output -InputObject (Get-WMIObject -NameSpace ($Namespace) -Class ($Class))
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
Else
|
Else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user