Matthewl 发表于 2018-9-3 10:50:51

Searching the Active Directory with PowerShell-nick

Function get-dn ($SAMName)  {
  $root = ''
  $searcher = new-object System.DirectoryServices.DirectorySearcher($root)
  $searcher.filter = "(&(objectClass=user)(sAMAccountName= $SAMName))"
  $user = $searcher.findall()
  if ($user.count -gt 1)
  {
  $count = 0
  foreach($i in $user)
  {
  write-host $count ": " $i.path
  $count = $count + 1
  }
  $selection = Read-Host "Please select item: "
  return $user[$selection].path
  }
  else
  {
  return $user.path
  }
  }
  $Name = $args
  $path = get-dn $Name
  "'" + $path + "'"

页: [1]
查看完整版本: Searching the Active Directory with PowerShell-nick