Professional Documents
Culture Documents
com/powershell-commands/#office365
This is the ultimate collection of PowerShell commands for Active Directory, Office
365, Windows Server and more.
These commands will help with numerous tasks and make your life easier.
Table of Contents:
Get-ADDomain
1 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Get-ADFineGrainedPasswordPolicy -filter *
Get-ADDefaultDomainPasswordPolicy
2 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Get-ADUser -Filter *
3 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Search-ADAccount -LockedOut
Search-ADAccount -AccountDisabled
4 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
You will need the distinguishedName of the user and the target OU
AD Group Commands
Get All members Of A Security group
Get-ADGroup -filter *
5 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
AD Computer Commands
Get All Computers
This will list all computers in the domain
Get-AdComputer -filter *
6 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
This will list all the computers in the domain and only display the hostname
7 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
8 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Get-Mailbox email-address | fl
Get-MailboxFolderPermission username:calendar
9 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
get-service
get-process
get-netadapater
10 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
You can also run this single line to get last boot time
systeminfo | more
Enter-PSSession -ComputerName
get-executionpolicy
11 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
set-executionpolicy unrestricted
$PSVersionTable
get-help command-name
get-help *keyword*
get-installedmodule
12 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Get-Module -ListAvailable
get-command
Find-Module *ntfs*
install-module NTFSSecurity
13 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
14 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Josh
January 29, 2019 at 10:13 pm
Reply
Robert Allen
January 29, 2019 at 10:59 pm
Reply
Joe Watson
March 1, 2019 at 2:23 pm
Thanks for the list, I’m looking for a script to show logged in users per
server showing user name, computer name and IP address. You have
anything like that yet?
Reply
Robert Allen
March 1, 2019 at 9:22 pm
15 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
This should get you the who is logged into a remote computer.
For something more complex that can query multiple computers check
out this article https://sid-500.com/2018/02/28/powershell-get-all-logged-
on-users-per-computer-ou-domain-get-userlogon/comment-page-1
/#comments
Reply
Ms.Tina
July 2, 2019 at 4:35 pm
Omg thank you so much; Now all I need to do is figure out how to get
power shell to grab history and list every change its ever made.. if its
possible. I hope it can. I’m trying to look for tampering on my laptop by
someone using PS. I know it’s been done but how, where, the extents –
hell even my registry has become questionable.
Reply
Mani
July 14, 2019 at 1:10 pm
16 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Reply
Vivek
July 23, 2019 at 5:44 pm
Hi Rob
Incredibly useful list, thanks – I’ve been trying to analyze disabled user
accounts on AD; what I saw was the export for disabled accounts didn’t
contain a few corporate IDs I know are disabled (they also have
UserAccountControl 514, which I understand indicates a disabled
account). So i’m questioning the completeness of the export I’ve got – any
ideas why this might be the case? Is it possible for a few disabled accounts
to not show up in an export of disabled AD accounts (admittedly these are
quite few in number but I wanted to check regardless). thanks.
VS.
Reply
17 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
NavaL
July 29, 2019 at 2:17 pm
Its awesome
Reply
Vivek
August 7, 2019 at 4:05 pm
Great info on here Robert, amazing stuff! I’m looking to export a list of all
accounts where interactive logon has been enabled (or disabled,
whichever is easier) – basically to test whether a service or non-corporate
account is accessible by a human. Is there a powershell script that does
this for me? I would hope yes!
Reply
Egyir
August 28, 2019 at 1:08 pm
Great job and thanks for the list, I’m searching for a script to extend the
expiration date for a User Account NOT TO SET TO
PASSWORDNOTREQUIRED OR PASSWORDNEVEREXPIRE . Kindly
help me out?
18 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
THANK YOU.
Reply
Harold
January 12, 2022 at 6:46 am
Reply
19 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Dustin
September 10, 2019 at 8:42 am
Reply
JSchauer
September 19, 2019 at 9:11 pm
This list will go a long way in helping me get comfortable with PowerShell.
Thanks for taking the time to create this list.
Reply
Robert Allen
September 19, 2019 at 11:32 pm
No problem
Reply
Alexey
September 26, 2019 at 8:14 am
20 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Thank you very much, this list will be very useful for me and my team!
Reply
boima
October 18, 2019 at 9:09 am
Hello Sir
For exampe to display the folders on the C drive used this: get-childitem
-force | select fullname
It displays the folders and also show the sizes unfortunately, it does not
show all folder sizes only the first two folders.
I will be very happy if you would look at the code and please asist me with
it. (Powershell)
21 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Best regards
Boima
Reply
Robert Simpson
December 14, 2019 at 2:21 am
Reply
Reshma
November 20, 2019 at 7:43 am
Reply
UVNAIDU
February 18, 2020 at 1:26 pm
22 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Reply
John Hughes
February 20, 2020 at 2:00 pm
should be shown as
Get-ADUser [username] -Properties * | Select name, department, title
Reply
Robert Allen
February 22, 2020 at 2:54 pm
23 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Thanks
Reply
Aro
February 24, 2020 at 1:52 am
Awesome
Reply
Jenn
March 26, 2020 at 3:21 pm
I don’t know who wrote this awesome list of PS scripts but they deserve a
RAISE, a toast of glasses, a high-five with elbows (during Covid-19) a
standing ovation, and a big bear hug!!! Thank you so much from the
bottom of my heart !!!! You ROCK, John.
Reply
Robert Allen
November 7, 2020 at 10:55 pm
24 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Thanks Jenn!
Reply
NAGENDRA RATHORE
April 1, 2020 at 3:12 pm
Awesome, I am looking for a script which will give output of all computers
in the AD with SMTP service status.
Reply
Leo
June 9, 2020 at 2:24 pm
Hello
Its really very useful. Thank you. I have one query. Please help me.
I want to add only member server (Without Domain Controller) to particular
OU
(OR)
Please provide a script for removing Domain Controller (Not member
server) from OU.
Thanks in advance
Regards
Leo.
25 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Reply
Robert Allen
January 1, 2021 at 6:18 pm
You can move objects with the move-adobject cmdlet. Use the
distinguished name of the object you want to move then the DN of the
path. Example below. This would move PC1 from the default OU to OU
Accounting.
Move-ADObject -Identity
“CN=PC1,CN=Computers,DC=ad,DC=activedirectorypro,DC=com”
-TargetPath “OU=Accounting,OU=ADPRO
Computers,DC=ad,DC=activedirectorypro,DC=com”
Reply
Ross
June 22, 2020 at 3:22 pm
Would you know how to list the users who have permission to send to a
distribution list?
Reply
26 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
zim
August 20, 2020 at 2:00 pm
Reply
secu04
August 29, 2020 at 2:07 pm
Very good commands. I am looking for a command that lists the logon
history of all users who opened their windows session. i have active
directory 2008. i dont have third party tools.
Reply
Robert Allen
September 20, 2020 at 1:37 pm
27 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Getting logon history is difficult because the real logon event is stored on
the local computer, not ain Active Directory.
Reply
daylon
September 9, 2020 at 2:03 pm
Hi Guys
How would I push an address say for example the address is ” 10 xyz
street” across to an entire OU, lets call the OU Test?
Regards
Daylon
Reply
Robert Allen
November 7, 2020 at 10:30 pm
28 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Hi Daylon,
This can definitely be done with PowerShell but can get a bit complex.
For that reason, I created an easy to use GUI tool called the AD Bulk
User Updater.
If you want to try the PowerShell option check out my post on updated
ProxyAddress.
https://activedirectorypro.com/how-to-bulk-update-proxyaddresses-
attribute/
Reply
Santosh
September 22, 2020 at 10:05 pm
Reply
29 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Robert Allen
September 26, 2020 at 1:13 pm
Reply
Tom Cipriano
November 7, 2020 at 1:40 am
Reply
cyp000000
January 30, 2021 at 6:26 am
30 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
Hi,
Do you know of a way to extract SYSTEM accounts via PS from Active
Directory. Example RPCservice.
get-aduser doesn’t seem to list them
The below list them, but also regular account. I need only SYSTEM
accounts and also some values from them.
get-wmiobject -class “win32_account” -namespace “root\cimv2” | sort
caption | format-table caption, __CLASS, FullName
Reply
Rohit Singh
February 15, 2021 at 7:16 am
Reply
James Bond
February 16, 2021 at 1:44 pm
31 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
https://stackoverflow.com/questions/5072996/how-to-get-all-groups-that-
a-user-is-a-member-of
Reply
Kevin Eisert
May 12, 2021 at 3:06 pm
I am having trouble figuring out how to use PowerShell to batch change the
Active Directory domain for a collection of users. The company went
through a name change, and I need to make this modification. Can anyone
help me?
Reply
32 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
33 of 34 22-03-2022, 00:07
Huge List Of PowerShell Commands for Active Directory, Office 365 a... https://activedirectorypro.com/powershell-commands/#office365
34 of 34 22-03-2022, 00:07