0% found this document useful (0 votes)
5 views6 pages

PowerShell Commands

This document provides a comprehensive guide to various Windows PowerShell commands for managing files, directories, users, and services. It includes commands for listing, copying, moving, and deleting files, as well as managing user accounts and permissions. Additionally, it covers package management, disk partitioning, and process monitoring, making it a valuable resource for PowerShell users.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

PowerShell Commands

This document provides a comprehensive guide to various Windows PowerShell commands for managing files, directories, users, and services. It includes commands for listing, copying, moving, and deleting files, as well as managing user accounts and permissions. Additionally, it covers package management, disk partitioning, and process monitoring, making it a valuable resource for PowerShell users.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Windows Powershell Commands

List directories and files


ls [location]

Example:
Invalid command or path

List hidden directories and files


ls -force [location]

Example:
list directory c:\ -force

Get help from a command


get-help [command]

Example:
get-help ls

Get complete help


get-help [command] -full

Example:
get-help ls -full

Print the current directory


pwd

Change directory
cd [relative or absolute path of directory]

Examples:
cd C:\users\agustin\documents

cd documents

cd ..\documents

cd ..

Create a new directory


mkdir [directoryname]

Example:
mkdir my_super_directory

mkdir "my super directory"

mkdir my super directory

Command History
history

You can also use Ctrl + R and start typing a previously used command.
Clean the screen
clear

1
Copy files and directories
cp [file] [destination location]

Example:
copy my_file c:\users\Augustin\my_folder

cp *.jpg c:\users\agustin\images

cp .\my_directory c:\users\August\desktop -recurse -verbose

Move and rename files and directories


mv [source/file location] [destination/file location]

Examples:
move my_yellow_file to my_new_green_file

move my_file c:\users\augustin\documents

move *.jpg c:\users\agustin\images

Removing files and directories


rm [file or directory]

Examples
remove archivo.txt

remove important_system_file -force

rm .\directory_to_delete

Remove .\directory_to_delete -recurse

Show the contents of a file


cat [file name]

Examples:
cat file.txt

Show the first 10 lines of the file:


cat lista_de_cosas.txt -head 10

Show the last 10 lines of the file:


cat list_of_things.txt -tail 10

Show a long paginated file:


more [file name]

Example:
more long_file.txt

Searching within files


select-string [text to search] [where to search]

Examples:
select-string vacation farm_file.txt
select-string vacation *.txt

Searching within directories


ls [location] -recurse -filter [what I want to search]

2
Example:
ls "C:\Program Files\" -recurse -filter *.exe

Entry, exit and the pipe


Add information and overwrite a file.
echo "hello world!" > my_file.txt

Add information to the previous content in a file.


echo "How are you?" >> my_file.txt

Pass the output of one command as input to another.


cat recipe.txt | select-string 'flour'

Combine several commands.


cat receta.txt | select-string 'flour' > filtered.txt

Redirect errors to a text file.


remove system_file.txt 2> errors.txt

Do not show errors.


ls /dir 2> $null

View user and group information


Show the users of the local machine.
get-localuser

Show the groups of the local machine.


get-localgroup

Show the users that are in a certain group.


get-localgroupmember [group name]

Passwords
Change a user's password
net user [user] ["password"]

Example:
net user agustin "123456"

Change a user's password but do not display it in


the command line.
net user [user] *

Force a user to change their password at the next login.


net user [user] /logonpasswordchge:yes

Example:
net user agustin /logonpasswordchge:yes

Add and remove users


Add a new user with a password.
net user [user] [password] /add

Add a user with a password and force them to change it at the next login.
net user [user] [password] /add /logonpasswordchge:yes

Remove a user.
net user [user] /del

3
File permissions
Check the permissions of a file or directory
icacls [file or directory]

Modify permissions
icacls [file or directory] /grant '[user]:[permissions]'

Examples:
Modify a user permission:
icacls 'D:\Test\' /grant 'Everyone:(OI)(CI)(R)'

Remove user permissions.


icacls 'D:\Test\' /remove 'Users'

Special file permissions


Compressed files
Compress a file
compress-archive -path [file or folder] [compressed file name]

Example:
compress-archive -path c:\users\my_folder backup.zip

Package dependencies
Locate a package
find-package [package name] -includedependencies

Example:
find-package sysinternals -includedependencies

Add package search provider


register-packagesource -name [name] -providername [name] -location [url]

Example:
register-packagesource -name chocolatey -providername chocolatey -location
http://chocolatey.org/api/v2

Install a package
install-package -name [package name]

Example
install-package -name sysinternals

Verify packages
get-package [package name]

Uninstall packages
uninstall-package -name [package name]

Disk partitioning and formatting of a file system


diskpart

List the current disks in the system.


list disk

Select the disk to work on.

4
select disk [disk number]

Remove all partition or volume formatting from the disk.


clean

Create partition.
create primary partition

Select partition.
select partition [partition number]

Mark the partition as active.


active

Format the disk with NTFS system


format fs=ntfs label=[label] quick

Files
Symbolic links
Create a symbolic link to a file.
If the name of the source file is changed, the link will remain
rotor.
mklink [link name] [source file]

Example:
mklink symlink file.txt

Physical ties
Create a physical link to a file.
If the source file name is changed, the link will remain
working.
mklink /h [link name] [source file]

Example:
mklink /h hardlink_file arhivo.txt

Processes
List the processes
This command is for PowerShell only.
get-process

This command is for Powershell or cmd.


tasklist

Delete a process
taskkill /pid [process number]

Signals
signals intelligence

To interrupt a process, it is necessary to send the SigInt signal by pressing the keys Ctrl + C.
Resource monitoring
Show the top three processes that consume the most resources
of the microprocessor.
get-process | sort cpu -descending | select -first 3 -property id, processname, cpu

5
Management services
Get-Service command
Check the status of a service.
get-service [service]

View more information about a service


get-service [service] | formatlist *

Stop a service. You must be an administrator.


stop-service [service]

Start a service. You must be an administrator.


start-service [service]

List all system services.


get-service

You might also like