This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Load the ConfigurationManager Module | |
Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1" | |
#Change location to my CMSite Provider | |
Cd DEX: | |
#Load the Default Parameter Values for Get-WMIObject cmdlet | |
$PSDefaultParameterValues =@{"get-wmiobject:namespace"="Root\SMS\site_DEX";"get-WMIObject:computername"="DexSCCM"} | |
#Add the Assembly Reference | |
Add-Type -Path "$(Split-Path $env:SMS_ADMIN_UI_PATH)\Microsoft.ConfigurationManagement.DesiredConfiguration.dll" -Verbose | |
Add-Type -Path "$(Split-Path $Env:SMS_ADMIN_UI_PATH)\Microsoft.ConfigurationManagement.ApplicationManagement.dll" | |
#Creating Type Accelerators - for making assemlby refrences easier later | |
$accelerators = [PSObject].Assembly.GetType('System.Management.Automation.TypeAccelerators') | |
$accelerators::Add('SccmSerializer',[type]'Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer') | |
#create the CI and store it in a variable | |
$testCI = New-CMConfigurationItem -CreationType WindowsOS -Name "DexterPStest" -Description "Testing PS automation" -Verbose | |
#load the XML | |
$oldxml = New-Object -TypeName xml | |
$oldxml.LoadXml($($testCI.SDMPackageXML)) | |
#now create a Folder setting | |
$foldersetting = New-Object -TypeName Microsoft.ConfigurationManagement.DesiredConfiguration.Settings.FolderSetting -ArgumentList "File_$([guid]::NewGuid())",'test','PS Automation' | |
$foldersetting.path = "C:\temp\test" | |
$foldersetting.FolderName = "Dexter" | |
#create the XML Writer Settings | |
$settings = New-Object system.Xml.XmlWriterSettings | |
$settings.Indent = $true | |
$settings.OmitXmlDeclaration = $false | |
$settings.NewLineOnAttributes = $true | |
# Create a new Writer | |
$writer = [system.xml.XmlWriter]::Create("C:\Temp\FolderSetting.xml", $settings) | |
#Now let's serialize the XML and let it be written to our XML Writer | |
$foldersetting.SerializeToXml($writer) | |
#Flush the contents to the file | |
$writer.Flush() | |
#disposr the Writer Object | |
$writer.Dispose() | |
#let's load the XML now | |
$FolderXML = New-Object -TypeName xml | |
$FolderXML.Load("C:\Temp\FolderSetting.xml") | |
#import the new Folder XML node to the old xml | |
$import = $oldxml.ImportNode($FolderXML.folder,$true) | |
#now add the above imported XML node | |
$oldxml.DesiredConfigurationDigest.OperatingSystem.Parts.AppendChild($import) | |
#save the new xml | |
$oldxml.Save("C:\temp\newxml.xml") | |
#tried setting the SDMPackageXML and using the put() method but it doesn't work. | |
#Below cmdlet updates the XML | |
Set-CMConfigurationItem -DesiredConfigurationDigestPath C:\temp\newxml.xml -Name $testCI.Localizeddisplayname -Verbose | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would LOVE LOVE LOVE LOVE to be able to do this for script settings, but have been able to find any documentation on it other than what you have written. Would you be able to help me out on this?
Trying to automatically create CIs with Script Settings that fail if the script outputs anything