PowerShell测试连接和Active Directory输入 [英] PowerShell Test-connection and Active Directory Input

查看:63
本文介绍了PowerShell测试连接和Active Directory输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习powershell,我正在编写一个脚本,从AD中提取计算机名称并将它们放入Test-connection cmdlet以确定它是否有效。

I am just learning powershell, and I"m working to write a script that pulls computer names from AD and puts them into a Test-connection cmdlet to determine if its valid.

clear-host
import-module activedirectory
$workstations = Get-ADComputer -Filter '*' -SearchBase "OU=CMSD,OU=Windows XP,OU=Workstations,DC=TECH,DC=LOCAL" | FT Name
Foreach($w in $workstations)
    {
        Test-Connection -ComputerName $w -Count 1
    }

当我运行脚本时,我收到所有条目的以下错误:

when i run the script, i receive the following error for all entries:

Test-Connection : Testing connection to computer 'Microsoft.PowerShell.Commands.Internal.Format.GroupEndData' failed: The requested name is valid, but no data of the requested type was found
At line:6 char:24
+         Test-Connection <<<<  -computername $w -Count 1
    + CategoryInfo          : ResourceUnavailable: (Microsoft.Power...at.GroupEndData:String) [Test-Connection], PingException
    + FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand

我认为当数组进入Test-connection cmdlet时,它会添加字符串字符,例如"name = computer"等。而不只是计算机名称。  我不知道如何在powershell中编辑字符串。  

I'm thinking that when the array is going into the Test-connection cmdlet, its adding string characters such as "name=computer" and not just the computer name.  I don't know how to edit strings in powershell.  

感谢您的任何帮助,谢谢。

any help is appreciated, thank you.




推荐答案

当您返回计算机时,您会获得多个属性 - DN,Name, SID等。你需要用虚线表示法指出你想要的属性。

When you return a computer you get multiple properties - DN, Name, SID, etc. You need to indicate what property you want using dotted notation.

... {
        Test-Connection -ComputerName


w.Name -Count 1
} ...
w.Name -Count 1 }...

您还可以在获取Get时返回名称-ADComputer通过将它管道输出到Select-Object。如果执行此选项,则您的变量不需要带点的符号(.Name)。

You can also only return the Name when you do your Get-ADComputer by piping it to Select-Object. If you do this option, your variable would not need the dotted notation (.Name).


w就是您所需要的,因为它只包含Name属性。

w is all you would need, since it would only contain the Name property.
Get-ADComputer -Filter * -SearchBase ... | select Name


哦,我刚刚意识到你正在将它传递给格式表 - 摆脱它!做上面两个选项中的一个,你应该弄清楚这一点。选择选项可能是最佳选择,因为您将返回一组较小的信息。

Oh my, I just realized you are piping this to Format-Table - get rid of that! Do one of the two options above and you should have this figured out. Doing a select may be the best option since you will be returning a smaller set of information.


这篇关于PowerShell测试连接和Active Directory输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆