GET-ADCOMPUTER-CMDLET语法和真实示例

概要

获取一台或多台Active Directory计算机。
 

描述

该Get-ADComputercmdlet可以获取一台计算机或执行搜索以检索多台计算机。

该Identity参数指定要检索的Active Directory计算机。您可以通过计算机的专有名称(DN),GUID,安全标识符(SID)或安全帐户管理器(SAM)帐户名来识别计算机。您还可以将参数设置为计算机对象变量,例如,$<localComputerObject>或通过管道将计算机对象传递给Identity参数。

要搜索和检索多台计算机,请使用Filter或LDAPFilter参数。该Filter参数使用PowerShell表达式语言为Active Directory编写查询字符串。PowerShell表达式语言语法为Filter参数接收的值类型提供了丰富的类型转换支持。

有关Filter参数语法的更多信息,请键入Get-Help about_ActiveDirectory_Filter。如果已有LDAP查询字符串,则可以使用LDAPFilter参数。

此cmdlet检索默认的计算机对象属性集。要检索其他属性,请使用Properties参数。有关如何确定计算机对象的属性的更多信息,请参见Properties参数描述。
 

句法

Get-ADComputer [-AuthType {Negotiate | Basic}] [-Credential <PSCredential>] [-Properties <String[]>] [-ResultPageSize <Int32>]

[-ResultSetSize <Int32>] [-SearchBase <String>] [-SearchScope {Base | OneLevel | Subtree}] [-Server <String>] -Filter <String>

[<CommonParameters>]

 

Get-ADComputer [-Identity] <ADComputer> [-AuthType {Negotiate | Basic}] [-Credential <PSCredential>]

[-Partition <String>] [-Properties <String[]>] [-Server <String>] [<CommonParameters>]

 

Get-ADComputer [-AuthType {Negotiate | Basic}] [-Credential <PSCredential>] [-Properties <String[]>] [-ResultPageSize <Int32>]

[-ResultSetSize <Int32>] [-SearchBase <String>] [-SearchScope {Base | OneLevel | Subtree}] [-Server <String>] -LDAPFilter <String>

[<CommonParameters>]


 

例子

Get-ADComputer -Filter 'Name -like "*nsk*"' | select name | ogv

  • 返回名称中包含NSK的所有计算机
  • 仅显示计算机名称
  • 发送输出到GridView
     

Get-ADComputer -Filter 'Name -like "*dc0*"' -prop IPv4Address,operatingsystem,OperatingSystemServicePack,description | select name, `

description,ipv4address,operatingsystem,OperatingSystemServicePack | sort name |  export-csv `

c:\scripts\output\DC.csv -NoTypeInformation

  • 返回名称中包含DC0的所有计算机
  • 创建一个具有名称,描述,IP地址,操作系统名称,Service Pack级别的表
  • 按名称排序
  • 将结果导出到CSV文件
  • 摆脱了CSV导出中包含的“ typeInformation”字段
     

get-adcomputer -filter 'Description -like "*WSUS*" -prop * | select name, `

@{Name='ManagedBy';Expression={(Get-ADUser ($_.managedBy)).samaccountname}}, description

  • 查找带有包含WSUS的描述的计算机
  • 返回服务器名称,服务器描述和“管理者”字段
  • 将“  DN 管理转换为SAMAccountName
     

get-adcomputer -filter 'OperatingSystem -like "*server*"' -prop MemberOf, managedby, description |

Where-Object {

    ( $_.MemberOf -notcontains $Group1.DistinguishedName ) -and

    ( $_.MemberOf -notcontains $Group2.DistinguishedName ) -and

    ( $_.MemberOf -notcontains $Group3.DistinguishedName ) -and

    ( $_.MemberOf -notcontains $Group4.DistinguishedName ) -and

    ( $_.MemberOf -notcontains $Group5.DistinguishedName ) -and

    ( $_.MemberOf -notcontains $Group6.DistinguishedName ) -and

    ( $_.MemberOf -notcontains $Group7.DistinguishedName )

} | Select-Object name, @{Name='ManagedBy';Expression={(Get-ADUser ($_.managedBy)).samaccountname}}, description | sort name |  ogv

  • 从七个广告组读取
  • 搜索操作系统名称包含服务器 且不属于列出的七个组的计算机的计算机(即很好的搜索,以尝试查找诸如“未分配给补丁程序组”之类的内容)
     

Get-ADComputer -Filter 'operatingsystem -like "*server*"' -Properties whenCreated, description | Where-Object `

{ ((Get-Date) - $_.whenCreated).Days -lt 40} | select name, description, whencreated | sort whencreated | `

Export-csv c:\scripts\output\servers-last40-days.csv -NoTypeInformation

  • 在“操作系统名称”字段中搜索带有“服务器”的计算机
  • 筛选列表以反对最近40天创建的对象
  • 导出为CSV

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值