11function New-CitrixTemplate {
22 <#
33 . SYNOPSIS
4- Creates a new Citrix Optimizer base template with the parameters passed in .
4+ Creates a new Citrix Optimizer base template.
55
66 . DESCRIPTION
77 This function will create a new Citrix Optimizer base template with the parameters passed in. It will auto generate a new GUID and Last Updated date based upon when the function is run.
@@ -27,12 +27,15 @@ function New-CitrixTemplate {
2727 . EXAMPLE
2828 PS> New-CitrixTemplate -Path 'template.xml' -DisplayName 'Citrix Optimization Template' -Description 'This is a new Citrix Optimization template' -Author 'Dave Brett'
2929 Generates a new template file with the above values.
30+ . EXAMPLE
31+ PS> $Template = New-CitrixTemplate -Path 'template.xml' -DisplayName 'Citrix Optimization Template' -Description 'This is a new Citrix Optimization template' -Author 'Dave Brett'
32+ Generates a new template file with the above values and assigns the return object to the variable $Template
3033
3134 . LINK
32- https://github.com/dbretty/Citrix.Optimizer.Template /blob/main/Help/New-CitrixTemplate.MD
35+ https://github.com/dbretty/CitrixOptimizerAutomation /blob/main/Help/New-CitrixTemplate.MD
3336#>
3437
35- [CmdletBinding (SupportsShouldProcess = $true , ConfirmImpact = ' Low ' )]
38+ [CmdletBinding ()]
3639
3740Param (
3841 [Parameter (
@@ -50,8 +53,7 @@ Param (
5053 [Parameter (
5154 ValuefromPipelineByPropertyName = $true , mandatory = $true
5255 )]
53- [System.String ]$Author ,
54- [Switch ] $Force
56+ [System.String ]$Author
5557)
5658
5759begin {
@@ -67,71 +69,66 @@ begin {
6769
6870process {
6971
70- if ($Force -or $PSCmdlet.ShouldProcess ())
71- {
72+ if (! (Get-Template - Path $Path )){
7273
73- if (! (Get-Template - Path $Path )){
74+ # Set The Formatting
75+ write-verbose " Set the XML formatting"
76+ $xmlsettings = New-Object System.Xml.XmlWriterSettings
77+ $xmlsettings.Indent = $true
78+ $xmlsettings.IndentChars = " "
79+
80+ # Set the File Name Create The Document
81+ write-verbose " Create Base XML Template"
82+ $XmlWriter = [System.XML.XmlWriter ]::Create($Path , $xmlsettings )
83+
84+ # Write the XML Decleration and set the XSL
85+ $xmlWriter.WriteStartDocument ()
86+
87+ # Start the Root Element
88+ write-verbose " Write Root element for template"
89+ $xmlWriter.WriteStartElement (" root" )
90+ $xmlWriter.WriteAttributeString (" xmlns" , " xsd" , $null , " http://www.w3.org/2001/XMLSchema" )
91+ $xmlWriter.WriteAttributeString (" xmlns" , " xsi" , $null , " http://www.w3.org/2001/XMLSchema-instance" )
92+
93+ # Start the Metadata Element
94+ write-verbose " Write metadata element for template"
95+ $xmlWriter.WriteStartElement (" metadata" )
96+
97+ # Write Metadata details
98+
99+ # Get Date and GUID for metadata
100+ [string ]$NewGuid = New-Guid
101+ $GUID = $NewGuid.ToUpper ()
102+ $LastUpdate = (Get-Date ).ToString(" MM/dd/yyyy" )
103+
104+ # Write metadata elements to base template
105+ $xmlWriter.WriteElementString (" schemaversion" , " 2.0" )
106+ $xmlWriter.WriteElementString (" version" , " 1.0" )
107+ $xmlWriter.WriteElementString (" id" , $GUID )
108+ $xmlWriter.WriteElementString (" displayname" , $DisplayName )
109+ $xmlWriter.WriteElementString (" description" , $Description )
110+ $xmlWriter.WriteElementString (" category" , " OS Optimizations" )
111+ $xmlWriter.WriteElementString (" author" , $Author )
112+ $xmlWriter.WriteElementString (" lastupdatedate" , $LastUpdate )
74113
75- # Set The Formatting
76- write-verbose " Set the XML formatting"
77- $xmlsettings = New-Object System.Xml.XmlWriterSettings
78- $xmlsettings.Indent = $true
79- $xmlsettings.IndentChars = " "
80-
81- # Set the File Name Create The Document
82- write-verbose " Create Base XML Template"
83- $XmlWriter = [System.XML.XmlWriter ]::Create($Path , $xmlsettings )
84-
85- # Write the XML Decleration and set the XSL
86- $xmlWriter.WriteStartDocument ()
87-
88- # Start the Root Element
89- write-verbose " Write Root element for template"
90- $xmlWriter.WriteStartElement (" root" )
91- $xmlWriter.WriteAttributeString (" xmlns" , " xsd" , $null , " http://www.w3.org/2001/XMLSchema" )
92- $xmlWriter.WriteAttributeString (" xmlns" , " xsi" , $null , " http://www.w3.org/2001/XMLSchema-instance" )
93-
94- # Start the Metadata Element
95- write-verbose " Write metadata element for template"
96- $xmlWriter.WriteStartElement (" metadata" )
97-
98- # Write Metadata details
99-
100- # Get Date and GUID for metadata
101- [string ]$NewGuid = New-Guid
102- $GUID = $NewGuid.ToUpper ()
103- $LastUpdate = (Get-Date ).ToString(" MM/dd/yyyy" )
104-
105- # Write metadata elements to base template
106- $xmlWriter.WriteElementString (" schemaversion" , " 2.0" )
107- $xmlWriter.WriteElementString (" version" , " 1.0" )
108- $xmlWriter.WriteElementString (" id" , $GUID )
109- $xmlWriter.WriteElementString (" displayname" , $DisplayName )
110- $xmlWriter.WriteElementString (" description" , $Description )
111- $xmlWriter.WriteElementString (" category" , " OS Optimizations" )
112- $xmlWriter.WriteElementString (" author" , $Author )
113- $xmlWriter.WriteElementString (" lastupdatedate" , $LastUpdate )
114-
115- $xmlWriter.WriteEndElement ()
116-
117114 $xmlWriter.WriteEndElement ()
118-
119- # End, Finalize and close the XML Document
120- $xmlWriter .WriteEndDocument ()
121- $xmlWriter .Flush ()
122- $xmlWriter.Close ()
123- write-verbose " Base XML template created "
124-
125- # Set return value
126- $Return .complete = $true
127-
128- } else {
129-
130- # Template already exists, write verbose and error stream
131- write-verbose " The template file $ ( $Path ) already exists "
132- write-error " The template file $ ( $Path ) already exists "
133-
134- }
115+
116+ $xmlWriter .WriteEndElement ()
117+
118+ # End, Finalize and close the XML Document
119+ $xmlWriter.WriteEndDocument ()
120+ $xmlWriter .Flush ()
121+ $xmlWriter .Close ()
122+ write-verbose " Base XML template created "
123+
124+ # Set return value
125+ $Return .complete = $true
126+
127+ } else {
128+
129+ # Template already exists, write verbose and error stream
130+ write-verbose " The template file $ ( $Path ) already exists "
131+ write-error " The template file $ ( $Path ) already exists "
135132
136133 }
137134
0 commit comments