powershell 从XML文件导入设置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 从XML文件导入设置相关的知识,希望对你有一定的参考价值。

<#
.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
	}
}

以上是关于powershell 从XML文件导入设置的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint PowerShell 从CSV文件导入数据到列表

Powershell 创建炫丽美观的Html报表

Powershell 创建炫丽美观的Html报表

在 Powershell 中从非常大的 XML 文件中删除节点

如何从 PowerShell 运行 *.exe 文件

如何使用powershell从xml中获取属性值?