快速的问题,我需要拉OS版本200+服务器..我发现做到这一点通过问题拉动主机名和操作系统版本 - PowerShell的
$servers = get-content "C:\Automation\Servers.txt"
Get-WmiObject -class win32_operatingsystem -ComputerName $servers | Select-Object Caption
但是结果踢中后卫是结合的方式这样
Caption
-------
Microsoft(R) Windows(R) Server 2003, Standard Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft Windows Server 2008 R2 Standard
Microsoft Windows Server 2008 R2 Datacenter
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003, Enterprise Edition
Microsoft(R) Windows(R) Server 2003 Standard x64 Edition
Microsoft(R) Windows(R) Server 2003, Standard Edition
现在的主要问题是一些失败的,所以我不能只是倒计时列表,并把名字对他们...有没有办法让旁边的程序从我的文件写的主机名版本?还是我找错了树....
我没有找到一个办法做到这一点与IP这里是指不使用其使用“System.Net WMI对象这样
$servers = get-content "C:\Automation\Servers.txt"
foreach ($server in $servers) {
$addresses = [System.Net.Dns]::GetHostAddresses($server)
foreach($a in $addresses) {
"{0},{1}" -f $server, $a.IPAddressToString
}
但是地址。 Dns] :: GetHostAddresses($ server)“所以我不知道如何适应我的需要,任何帮助将是伟大的。感谢你的帮助。
PERFECT !!!这正是我需要的......现在这是如何工作的?我真的不明白“{0},{1}”“是干什么的?这种行为是否被称为某种东西,我可以谷歌和了解它? – Mal229
这是创建一个格式化的字符串。你可以有 ''我的名字是{1},我最喜欢的颜色是{0}“-f”蓝色“,”Matt“ 马特将假设位置1在字符串中,蓝色将假设位置0创建 '”我的名字是马特,我最喜欢的颜色是蓝色“#: http://blogs.technet.com/b/heyscriptingguy/archive/2013/03/11/understanding-powershell-and-basic-string-formatting.aspx The链接包含了更深入的-f运算符,它可以做更多的事情。 – Matt