Private/Open-ISComponentConfiguration.ps1
<#
.SYNOPSIS Reads an IntelliSearch nuget configuration file .DESCRIPTION The command reads an IntelliSearch nuget configuration from a nuget package for use in instantiating a component .PARAMETER Path The path to the config file .NOTES The file has to be formatted as XML. The command will look for the IntelliSearchComponent node as the root. Subnodes of this node is used for the creation of an instance. See the Example-ISPSInstance.config for details. .INPUTS System.String .OUTPUTS System.Xml.XmlElement #> function Open-ISComponentConfiguration { [CmdletBinding(ConfirmImpact = "Low")] [OutputType()] param( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Path to component configuration file")] [Alias("PSPath")] [ValidateNotNullOrEmpty()] [ValidateScript( { Test-Path $_ -PathType Leaf})] [string] $Path ) $Path = Resolve-Path $Path $Xml = New-Object System.Xml.XmlDocument try { $Xml.Load($Path) } catch [System.Management.Automation.MethodInvocationException] { Throw [System.Management.Automation.MethodInvocationException] "Could not load the ISPSInstance.config file." } [System.Xml.XmlNamespaceManager]$ns = $xml.NameTable $ns.AddNamespace("Any", $xml.DocumentElement.NamespaceURI) try { $Result = $Xml.SelectNodes("//IntelliSearchComponent", $ns) } catch { Write-Error -Message "Could not find the correct node in configuration file" -Exception $_.Exception -ErrorAction:Stop } return $Result } |