我创建了一个文件config.ps1
,其中包含变量[服务器的详细信息]:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
#VMware Variables
$vcenterserver = "xyz@vsphere.local"
#Netview Variables
$netviewservers = "Sinpe.insta.org"
#Ping Servers
$pingservers = @("www.google.com","www.facebook.com","www.cricinfo.com")
#Xen Desktop Variables
$ddcserverconnection = "ddc.spawn.local"
#PVS Variables
$pvsservers = "ASPPVS02"
我为VMWare,SQL,Xen Desktop等编写了一些.ps1脚本。
Ex:我为PING编写了以下内容:
. .\config.ps1
$body += echo "-----------------------------Ping results for servers-------------------------------"`r`n""`r`n""
$body += foreach ($server in $pingservers) {
echo "$server"`r`n""
Test-Connection $server |
ft @{expression={$_.__server};label="Source Server"},
@{expression={$_.ipv4address};label="IP address"},
@{expression={$_.responsetime};label="Response time"} |
Out-String
}
Write-Output $body
我收到了以下回复:
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.Exchange.Management.PowerShell.E2010' is not installed on this computer. At C:\Users\admin\Desktop\config.ps1:1 char:1 + Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (Microsoft.Excha...owerShell.E2010:String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand -----------------------------Ping results for servers------------------------------- www.google.com Source Server IP address Response time ------------- ---------- ------------- DEV01 74.195.130.104 93 DEV01 74.195.130.104 93 DEV01 74.195.130.104 93 DEV01 74.195.130.104 96 facebook.com Source Server IP address Response time ------------- ---------- ------------- DEV01 74.163.87.234 348 DEV01 74.163.87.234 381 DEV01 74.163.87.234 294 DEV01 74.163.87.234 272 www.cricinfo.com Source Server IP address Response time ------------- ---------- ------------- DEV01 184.25.57.18 27 DEV01 184.25.57.18 157 DEV01 184.25.57.18 207 DEV01 184.25.57.18 73
我怎样才能消除这个错误?我希望脚本只从中获取$pingservers
变量而不是运行所有内容。