---
title: "Remove All Java Versions: A PowerShell Script Guide"
description: "Get rid of all Java versions with one PowerShell script. An invaluable guide for IT pros."
canonical: "https://adamtheautomator.com/get-aduser/"
---

# Remove All Java Versions: A PowerShell Script Guide

> Get rid of all Java versions with one PowerShell script. An invaluable guide for IT pros.

Source: https://adamtheautomator.com/get-aduser/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Remove All Java Versions: A PowerShell Script Guide](https://adamtheautomator.com/wp-content/uploads/2019/06/get-aduser-get-aduser.png)

# Remove All Java Versions: A PowerShell Script Guide

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)30 June 20194 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Active Directory](/tag/active-directory/)[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Finding a User Account with Identity](#finding-a-user-account-with-identity)
*   [The Get-ADUser Filter](#the-get-aduser-filter)
*   [Using Get-AdUser by OU](#using-get-aduser-by-ou)
*   [Using Alternate Credentials](#using-alternate-credentials)
*   [The PowerShell Get-AdUser Properties Parameter](#the-powershell-get-aduser-properties-parameter)
*   [Summary](#summary)

If you need to find Active Directory (AD) users in your domain, the Powershell Get-Aduser command is here. User accounts are assigned to employees, service accounts and other resources. Before you know it, AD user accounts are getting difficult to manage.

Using the `Get-AdUser` [PowerShell](https://adamtheautomator.com/tag/powershell/) cmdlet, you can get AD users many different ways. In this article, you’re going to learn a few of those ways and how to use this handy cmdlet.

> > _Manage and Report Active Directory, Exchange and Microsoft 365 with ManageEngine ADManager Plus. [Download Free Trial!](https://www.manageengine.com/products/ad-manager/tp/windows-active-directory-management-tool.html?utm_source=ata&utm_medium=website-listing&utm_campaign=admp-getaduser)_

## Prerequisites

To use the `Get-AdUser` cmdlet examples covered in this article, be sure you have the following:

*   On a Windows PC joined to an AD domain
*   Logged in as an AD user account
*   Have the [PowerShell Active Directory module](https://adamtheautomator.com/powershell-import-active-directory/) installed

## Finding a User Account with `Identity`

The `Get-AdUser` cmdlet has one purpose and one purpose only. It exists to provide as many options as possible to find domain users. If you already know the user name to look up, you can use the `Identity` parameter.

The `Identity` parameter allows you to provide one of four different identifiers.

*   distinguishedName (DN)
*   samAccountName
*   GUID
*   SID

Below you can see some examples of finding a user account using various identifiers. Notice that it returns a set of AD attributes for each user account.

```powershell
PS> Get-ADUser -Identity abertram


DistinguishedName : CN=Anne Bertram,OU=Marketing,DC=mylab,DC=local
Enabled           : False
GivenName         : Anne
Name              : Anne Bertram
ObjectClass       : user
ObjectGUID        : b98fd0c4-3d5d-4239-8245-b04145d6a0db
SamAccountName    : abertram
SID               : S-1-5-21-4117810001-3432493942-696130396-3142
Surname           : Bertram
UserPrincipalName : abertram@mylab.local



PS> Get-ADUser -Identity 'S-1-5-21-4117810001-3432493942-696130396-3142'


DistinguishedName : CN=Anne Bertram,OU=Marketing,DC=mylab,DC=local
Enabled           : False
GivenName         : Anne
Name              : Anne Bertram
ObjectClass       : user
ObjectGUID        : b98fd0c4-3d5d-4239-8245-b04145d6a0db
SamAccountName    : abertram
SID               : S-1-5-21-4117810001-3432493942-696130396-3142
Surname           : Bertram
UserPrincipalName : abertram@mylab.local



PS> Get-ADUser -Identity 'CN=Anne Bertram,OU=Marketing,DC=mylab,DC=local'


DistinguishedName : CN=Anne Bertram,OU=Marketing,DC=mylab,DC=local
Enabled           : False
GivenName         : Anne
Name              : Anne Bertram
ObjectClass       : user
ObjectGUID        : b98fd0c4-3d5d-4239-8245-b04145d6a0db
SamAccountName    : abertram
SID               : S-1-5-21-4117810001-3432493942-696130396-3142
Surname           : Bertram
UserPrincipalName : abertram@mylab.local
```

> _The most common attribute to use for the `Identity` parameter will be the `samAccountName` attribute._

## The `Get-ADUser` Filter

If you need to find more than one domain user or don’t know an identifier, use a filter. To do so, you’ve got a couple of parameters on hand called `Filter` and `LDAPFilter`.

Each filter parameter allows a user to provide a conditional statement. When this condition is met, `Get-AdUser` will return user accounts matching that condition.

The most common parameter to filter users is `Filter`. The `Filter` parameter allows you to create conditions that are like the PowerShell [`Where-Object`](https://adamtheautomator.com/powershell-where-object/ "Where-Object") command filter syntax.

The `Filter` parameter uses a language called PowerShell expression language syntax. This language is a bit like what you’d use with `Where-Object` but not quite. For a breakdown of how to use this filter, check out this [Active Directory and LDAP filters](https://adamtheautomator.com/ldap-filter/) article.

Below is an example of using the `Filter` parameter. This example provides an AD attribute (`givenName` in this example) and sets a condition. The filter is only allow users to return if they have a `givenName` equal to `Adam`.

```powershell
PS> Get-AdUser -Filter "givenName -eq 'Adam'"


DistinguishedName : CN=ADBertram,OU=Accounting,DC=mylab,DC=local
Enabled           : False
GivenName         : Adam
Name              : ADBertram
ObjectClass       : user
ObjectGUID        : 8ec5e2a8-1fda-42cb-9406-b1e6356dd457
SamAccountName    : ADBertram
SID               : S-1-5-21-4117810001-3432493942-696130396-3163
Surname           : Bertram
UserPrincipalName : ADBertram

DistinguishedName : CN=Hughes\, Adam,CN=Users,DC=mylab,DC=local
Enabled           : True
GivenName         : Adam
Name              : Hughes, Adam
ObjectClass       : user
ObjectGUID        : 96778db3-3dbd-4b83-9183-db111caa2791
SamAccountName    : ahughes
SID               : S-1-5-21-4117810001-3432493942-696130396-38201
Surname           : Hughes
UserPrincipalName :
```

The other filtering option is `LDAPFilter` which will not be covered in this article. For more information on the `LDAPFilter` and its syntax, check out this article on [Active Directory and LDAP filters](https://adamtheautomator.com/ldap-filter/).

## Using Get-AdUser by OU

By providing an identity or filter, PowerShell returns all users in the domain matching the criteria. It does not limit by OU. You’ll need to set up a “filter” for `Get-AdUser` to filter by OU using `Get-Aduser -SearchBase <OU>`.

Using the `SearchBase` parameter allows you to begin searching for a user account in a specific OU. The `SearchBase` parameter accepts an OU’s distinguished name (DN).

For example, you could find all users in the _MyUsers_ OU as shown below. Using the `Filter` of `*` means to match all user accounts.

```powershell
PS> Get-ADUser -Filter * -SearchBase 'OU=MyUsers,DC=domain,DC=local'
```

Perhaps you only want to find user accounts in a single OU and exclude any child OUs. In that case, you could use the `SearchBase` and `SearchScope` parameters. The `SearchScope` parameter defines how deep in the OU hierarchy you’d like to search.

For example, if you’d like to find all user accounts in an OU and all child OUs, you’d use `1` for the `SearchScope` value. If you’d like to search through _all_ child and grandchildren OUs, you’d use `2`.

Below is an example of searching for user accounts in the _MyUsers_ OU and all child OUs underneath it.

```powershell
PS> Get-ADUser -Filter * -SearchBase 'OU=MyUsers,DC=domain,DC=local' -SearchScope 2
```

## Using Alternate Credentials

By default, `Get-AdUser` will run under the context of the logged-on user. But you can also provide alternative credentials using the `Credential` parameter.

To authenticate with alternate credentials, create a _PSCredential_ object using `Get-Credential` like below:

```powershell
PS> $cred = Get-Credential
PS> Get-AdUser -Filter * -Credential $cred
```

> _For more information on credentials, check out [Using the PowerShell Get-Credential cmdlet and all things credentials](https://adamtheautomator.com/powershell-get-credential/)._

## The PowerShell Get-AdUser Properties Parameter

When you run `Get-AdUser`, you’ll immediately see only a few attributes are returned. You’ll also see that even when the output is piped to `Select-Object -Property *`, all attributes aren’t still returned.

To use PowerShell to get AD user attributes, use the `Property` parameter. This parameter accepts one or more comma-delimited attributes to show with the output.

Below you’ll see an example of using `Get-AdUser` to find all properties for all user accounts with a `givenName` of `Adam`. The output is snipped but you’ll see other familiar attributes like email address, password properties and more here.

```powershell
PS> Get-AdUser -Filter "givenName -eq 'Adam'" -Properties *


AccountExpirationDate                :
accountExpires                       : 9223372036854775807
AccountLockoutTime                   :
AccountNotDelegated                  : False
AllowReversiblePasswordEncryption    : False
AuthenticationPolicy                 : {}
AuthenticationPolicySilo             : {}
BadLogonCount                        : 0
badPasswordTime                      : 0
badPwdCount                          : 0
CannotChangePassword                 : False
CanonicalName                        : mylab.local/Accounting/ADBertram
........
```

> _Manage and Report Active Directory, Exchange and Microsoft 365 with ManageEngine ADManager Plus. [Download Free Trial!](https://www.manageengine.com/products/ad-manager/tp/windows-active-directory-management-tool.html?utm_source=ata&utm_medium=website-listing&utm_campaign=admp-getaduser)_

## Summary

The `Get-ADUser` cmdlet is a handy command to find AD user accounts, build reports and more. It’s a great way to pull AD users from a domain. For a breakdown of `Get-AdUser` and all parameters, read the help content by running `[Get-Help](https://adamtheautomator.com/powershell-get-help/) Get-AdUser`.

For many other examples of how to use `Get-AdUser`, check out the blog post [Active Directory Scripts Galore: Come and Get It!](https://adamtheautomator.com/active-directory-scripts/).

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fget-aduser%2F&text=Remove%20All%20Java%20Versions%3A%20A%20PowerShell%20Script%20Guide)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fget-aduser%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fget-aduser%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/11/image-23.png)

### [Managing Active Directory Groups with PowerShell: The Ultimate Guide](/powershell-ad-groups-guide/)

Learn how to manage Active Directory groups with PowerShell! This hands-on guide shows you how to query, create and modify AD groups using practical real-world

![](https://adamtheautomator.com/wp-content/uploads/2019/08/database-152091_1280.png)

### [Active Directory Database: PowerShell Monitoring Made Easy](/active-directory-database/)

Find the ntds.dit location and monitor your Active Directory database using PowerShell.

![](https://adamtheautomator.com/wp-content/uploads/2019/07/panic-1393619_1280.png)

### [How to Find Locked Out Users in Active Directory with PowerShell](/find-locked-out-users-in-active-directory-powershell/)

See what we can do to find locked out users in Active Directory with PowerShell!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
