Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Created September 22, 2015 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/84c8fbf7a196d94315a7 to your computer and use it in GitHub Desktop.
Save techthoughts2/84c8fbf7a196d94315a7 to your computer and use it in GitHub Desktop.
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