Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#Load the ConfigurationManager Module
Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"
#Change location to my CMSite Provider
#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')
#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
#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
#Flush the contents to the file
#disposr the Writer Object
#let's load the XML now
$FolderXML = New-Object -TypeName xml
#import the new Folder XML node to the old xml
$import = $oldxml.ImportNode($FolderXML.folder,$true)
#now add the above imported XML node
#save the new 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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment