0
我有这个脚本,我试图运行,我希望将备份DNS区域。我正尝试使用export-csv powershell cmdlet将此信息导出到csv文件中。最后,我使用dnscmd.exe命令将区域信息导出到文本文件并将它们存储在定义的位置。在运行PowerShell脚本来备份DNS区域时遇到Get-WmiObject问题
# Get Name of the server with env variable
$DNSSERVER=get-content env:computername
#—Define folder where to store backup —–#
$BkfFolder=”c:\windows\system32\dns\backup”
#—Define file name where to store Dns Settings
$StrFile=Join-Path $BkfFolder “input.csv”
#—-Check if folder exists. if exists, delete contents–#
if (-not(test-path $BkfFolder)) {
new-item $BkfFolder -Type Directory | Out-Null
} else {
Remove-Item $BkfFolder”\*” -recurse
}
#—- GET DNS SETTINGS USING WMI OBJECT ——–#
#– Line wrapped should be only one line –#
$List = get-WmiObject -ComputerName $DNSSERVER
-Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone
#—-Export information into input.csv file —#
#– Line wrapped should be only one line –#
$list | Select Name,ZoneType,AllowUpdate,@{Name=”MasterServers”;Expression={$_.MasterServers}},
DsIntegrated | Export-csv $strFile -NoTypeInformation
#— Call Dnscmd.exe to export dns zones
$list | foreach {
$path=”backup\”+$_.name
$cmd=”dnscmd {0} /ZoneExport {1} {2}” -f $DNSSERVER,$_.Name,$path
Invoke-Expression $cmd
}
# End of Script
#——————————————————————————————-#
当我运行该脚本,我得到以下信息:
我不完全相信这个消息是说。我尝试输入我的电脑名称,但这也不起作用。
任何帮助表示赞赏!
在'-Namespace ...'之前删除换行符,以便所有参数在同一行上 –
..或在$ DNSSERVER后添加空格和反引号... – thepip3r