From Zero to Hero: Mastering PowerShell for Windows Administrators

0

 Windows Logo + X = Access Shortcut 


Powershell for Administrator needed Permission



15 of the most commonly used PowerShell functions

  1. Get-Help: Provides detailed information about PowerShell cmdlets, including syntax and examples. It’s essential for learning how to use other cmdlets.

  2. Get-Command: Lists all available cmdlets, functions, workflows, aliases installed on your system. It’s useful for discovering new commands.

  3. Get-ChildItem: Retrieves the items and child items in one or more specified locations. It’s commonly used for directory and file listings.

  4. Set-Location: Changes the current directory to a specified path. It’s similar to the cd command in other shells.

  5. Get-Process: Displays a list of processes running on your local or a remote computer. It’s useful for monitoring system activity.

  6. Stop-Process: Stops one or more running processes. It’s handy for terminating unresponsive applications.

  7. Get-Service: Retrieves the status of services on a local or remote machine. It’s useful for managing Windows services.

  8. Start-Service: Starts a stopped service. It’s often used in scripts to ensure necessary services are running.

  9. Stop-Service: Stops a running service. It’s useful for stopping services that are no longer needed.

  10. Get-EventLog: Retrieves the events from event logs on the local or remote computers. It’s essential for system diagnostics and troubleshooting.

  11. Export-Csv: Converts objects into a series of comma-separated values (CSV) and saves them in a file. It’s useful for exporting data for analysis.

  12. Import-Csv: Reads a CSV file and converts it into objects. It’s commonly used for importing data into PowerShell.

  13. New-Item: Creates a new item, such as a file or directory. It’s useful for setting up new files and folders.

  14. Copy-Item: Copies an item from one location to another. It’s used for file and directory duplication.

  15. Remove-Item: Deletes an item, such as a file or directory. It’s essential for cleaning up files and directories.

Syntax

  1. Get-Help

    Get-Help Get-Process
    
  2. Get-Command

    Get-Command -Name Get-*
    
  3. Get-ChildItem

    Get-ChildItem -Path C:\Users
    
  4. Set-Location

    Set-Location -Path C:\Users
    
  5. Get-Process

    Get-Process -Name notepad
    
  6. Stop-Process

    Stop-Process -Name notepad
    
  7. Get-Service

    Get-Service -Name wuauserv
    
  8. Start-Service

    Start-Service -Name wuauserv
    
  9. Stop-Service

    Stop-Service -Name wuauserv
    
  10. Get-EventLog

    Get-EventLog -LogName System -Newest 10
    
  11. Export-Csv

    Get-Process | Export-Csv -Path C:\Temp\processes.csv
    
  12. Import-Csv

    Import-Csv -Path C:\Temp\processes.csv
    
  13. New-Item

    New-Item -Path C:\Temp\NewFolder -ItemType Directory
    
  14. Copy-Item

    Copy-Item -Path C:\Temp\file.txt -Destination C:\Backup
    
  15. Remove-Item

    Remove-Item -Path C:\Temp\file.txt

More Syntax You Can Use


Installing a Package (e.g., from NuGet)

PowerShell
Install-Package <Package Name> -Scope CurrentUser

Creating a Hidden Folder

PowerShell
New-Item -ItemType Directory -Path "C:\HiddenFolder" -Force -Attributes Hidden

Creating a Directory

PowerShell
New-Item -ItemType Directory -Path "C:\NewDirectory"

Requesting Administrator Permission

PowerShell
Start-Process PowerShell -Verb RunAs

Viewing Users

PowerShell
Get-ADUser -Filter *

Preventing Access to a Folder

Using File System Permissions:

PowerShell
icacls "C:\RestrictedFolder" /deny Everyone:(F)

Using Windows Security:

PowerShell
# This requires administrative privileges
icacls "C:\RestrictedFolder" /inheritance:disable
icacls "C:\RestrictedFolder" /deny Everyone:(F)


Post a Comment

0Comments

"Please keep your comments respectful and on-topic."
"Your email address will not be published."
"HTML tags are not allowed in comments."
"Spam comments will be deleted."

Post a Comment (0)