Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Import settings from an XML file
<#
.Synopsis
Get-Config function will pull in needed data from config file
.DESCRIPTION
Get-Config function will pull in needed data from config file.
#>
function Get-Config {
#specify the location of the config file
$csv = Import-Clixml -Path "C:\HypQC_Config.xml"
#Read the XML config file and load data into variables
try{
$Script:accountNumber = $csv.Account
$Script:dc = $csv.Datacenter
$Script:hostname = $csv.HostName
$Script:primaryIP = $csv.PrimaryIP
$Script:pNetMask = $csv.PrimaryNetMask
$Script:pgateway = $csv.PrimaryGateway
$Script:dns1 = $csv.DNS1
$Script:dns2 = $csv.DNS2
$Script:serviceNetIP = $csv.ServiceNetIP
$Script:serviceNetMask = $csv.ServiceNetMask
$Script:serviceGateway = $csv.ServicenetGateway
$Script:PubMacs = $csv.PubMacs
$Script:SNetMac = $csv.SNetMac
#check for any null values and halt if any found
Test-Nulls
}
catch{
Write-Host "ERROR - Config file properties could not be read. This is MOST LIKELY due to an empty field in the config file. Re-check the config file and try again." -ForegroundColor Red
Exit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.