Ten Handy PowerShell Commands
PowerShell is the command line included with Windows. It is a very handy tool for doing simple tasks without the GUI. In this guide, I’ll show you 10 tips that will improve your Windows Server experience and make your life easier.
Getting a Process
Rather than using the Task Manager or a similar tool, you can use PowerShell to retrieve information about a specific process and kill it, if needed. This will show the process ID (Id ProcessName
):
Get-Process ProcessName
Killing a Process
Once you have the process ID of a process, you can kill it:
Stop-Process -id PID
Getting Contents of a File
You can actually get the content of a file (for example a .txt
file) and view it in PowerShell:
Get-Content file.txt
Getting Item Information
You can get information about a certain file with the Get-Item
command. The cool thing about this is that you can use it to return multiple kinds of data, for example, you can see the last time somebody accessed a file:
$(Get-Item D:\Users\William\Desktop\file.txt).lastaccesstime
Adding a New Active Directory User
You can add an Active Directory user with the New-ADUser
command:
New-ADUser -SamAccountName "william" -GivenName "William" -Surname "Edwards" -DisplayName "William David Edwards"
Removing an Active Directory User
Removing an Active Directory user with PowerShell is possible too:
Remove-ADUser William
You can use a DN, SAM account name, SID, or an object GUID here.
Adding an Active Directory group
You can add an Active Directory group with PowerShell very easily:
New-ADGroup –name Staff” –groupscope Global
Use the name of the new Active Directory group for -name
and change the group scope if needed.
Removing an Active Directory group
Likewise, you can also remove an Active Directory group with PowerShell:
Remove-ADGroup Staff
Finding All Domain Controllers
You can find all domain controllers in a domain with PowerShell by finding out which computers are in the Domain Controllers group:
Get-ADGroupMember 'Domain Controllers'
Disabling an Active Directory account
You can disable an account in Active Directory to prevent a user from logging in. This can be done from PowerShell to avoid having to use the GUI for this simple task:
Disable-ADAccount William
Again, you can use a DN, SAM account name, SID, or an object GUID here.
Comments are closed.