Webbplatsens överlägg

Powershell scripts

Beginner Scripts (1–55)

  1. List All Running Processes
    Get-Process
  2. List All Services
    Get-Service
  3. Get IP Configuration
    Get-NetIPConfiguration
  4. Ping a Host
    Test-Connection google.com
  5. List Installed Programs
    Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName, DisplayVersion
  6. List Startup Programs
    Get-CimInstance -ClassName Win32_StartupCommand
  7. Check Disk Usage
    Get-PSDrive -PSProvider ’FileSystem’
  8. Check PowerShell Version
    $PSVersionTable.PSVersion
  9. Restart Computer
    Restart-Computer
  10. Shutdown Computer
    Stop-Computer
  11. Check System Uptime
    (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
  12. Create a New Local User
    New-LocalUser ”username” -Password (ConvertTo-SecureString ”password” -AsPlainText -Force)
  13. Add User to Local Group
    Add-LocalGroupMember -Group ”Administrators” -Member ”username”
  14. Set Execution Policy
    Set-ExecutionPolicy RemoteSigned
  15. Get Event Logs
    Get-EventLog -LogName System -Newest 10
  16. Kill a Process
    Stop-Process -Name notepad
  17. Get Computer Info
    Get-ComputerInfo
  18. Get Installed Hotfixes
    Get-HotFix
  19. List All Local Users
    Get-LocalUser
  20. List All Local Groups
    Get-LocalGroup
  21. Search for Files
    Get-ChildItem -Path C:\ -Recurse -Include *.txt
  22. Create a New Directory
    New-Item -Path ’C:\NewFolder’ -ItemType Directory
  23. Copy a File
    Copy-Item -Path ’C:\file.txt’ -Destination ’D:\file.txt’
  24. Move a File
    Move-Item -Path ’C:\file.txt’ -Destination ’D:\file.txt’
  25. Delete a File
    Remove-Item -Path ’C:\file.txt’
  26. Zip a Folder
    Compress-Archive -Path C:\Test -DestinationPath C:\Test.zip
  27. Unzip a File
    Expand-Archive -Path C:\Test.zip -DestinationPath C:\Test
  28. Set File Read-Only
    Set-ItemProperty -Path ’C:\file.txt’ -Name IsReadOnly -Value $true
  29. Get System Locale
    Get-WinSystemLocale
  30. Get Time Zone
    Get-TimeZone
  31. Set Time Zone
    Set-TimeZone -Id ”Central Europe Standard Time”
  32. Show Current Month/Year
    Get-Date -UFormat ”%B %Y”
  33. Display Current User
    whoami
  34. Test Internet Connection
    Test-Connection -ComputerName google.com -Count 2
  35. Show Network Adapters
    Get-NetAdapter
  36. Network Adapter Statistics
    Get-NetAdapterStatistics
  37. List Open TCP Ports
    Get-NetTCPConnection
  38. List Firewall Rules
    Get-NetFirewallRule
  39. Enable Firewall
    Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True
  40. Disable Firewall
    Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
  41. Set Static IP Address
    New-NetIPAddress -InterfaceAlias ”Ethernet” -IPAddress 192.168.1.100 -PrefixLength 24 -DefaultGateway 192.168.1.1
  42. Set DNS Servers
    Set-DnsClientServerAddress -InterfaceAlias ”Ethernet” -ServerAddresses (”8.8.8.8″,”8.8.4.4”)
  43. Flush DNS Cache
    Clear-DnsClientCache
  44. Release IP Address
    ipconfig /release
  45. Renew IP Address
    ipconfig /renew
  46. View ARP Table
    arp -a
  47. Show Routing Table
    route print
  48. Get MAC Address
    Get-NetAdapter | Select Name, MacAddress
  49. Enable Remote Desktop
    Set-ItemProperty -Path ’HKLM:\System\CurrentControlSet\Control\Terminal Server’ -Name ”fDenyTSConnections” -Value 0
  50. Enable Remote PowerShell Access
    Enable-PSRemoting -Force
  51. Stop a Service
    Stop-Service -Name ’wuauserv’
  52. Start a Service
    Start-Service -Name ’wuauserv’
  53. Restart a Service
    Restart-Service -Name ’wuauserv’
  54. Check Service Status
    Get-Service -Name ’wuauserv’
  55. List Scheduled Tasks
    Get-ScheduledTask

Advanced Scripts (56–100)

  1. Monitor System Performance in Real-Time
    Get-Counter -Counter ”\Processor(_Total)\% Processor Time” -SampleInterval 1 -MaxSamples 10
  2. List Active Directory Users
    Get-ADUser -Filter *
  3. Create New Active Directory User
    New-ADUser -Name ”John Doe” -GivenName ”John” -Surname ”Doe” -SamAccountName ”jdoe” -UserPrincipalName ”jdoe@domain.com” -Path ”OU=Users,DC=domain,DC=com”
  4. Modify Active Directory User
    Set-ADUser -Identity jdoe -Description ”Updated User Info”
  5. Remove Active Directory User
    Remove-ADUser -Identity jdoe
  6. List Active Directory Groups
    Get-ADGroup -Filter *
  7. Add User to Active Directory Group
    Add-ADGroupMember -Identity ”Admins” -Members ”jdoe”
  8. Get Group Memberships for User
    Get-ADUserMemberOf -Identity jdoe
  9. Get Active Directory Computer Info
    Get-ADComputer -Filter * | Select Name, OperatingSystem
  10. Set Computer Account Expiry
    Set-ADComputer -Identity ”Server01” -AccountExpirationDate ”12/31/2025”
  11. Get Active Directory Group Memberships
    Get-ADGroupMember -Identity ”GroupName”
  12. Get Installed Software on Remote Computer
    Invoke-Command -ComputerName ”RemotePC” -ScriptBlock {Get-WmiObject -Class Win32_Product}
  13. Export Active Directory Users to CSV
    Get-ADUser -Filter * | Export-Csv -Path ”C:\AD_Users.csv” -NoTypeInformation
  14. Import Active Directory Users from CSV
    Import-Csv ”C:\AD_Users.csv” | ForEach-Object { New-ADUser -Name $_.Name -SamAccountName $_.SamAccountName }
  15. Get File Hash (MD5, SHA-256)
    Get-FileHash ”C:\file.txt” -Algorithm SHA256
  16. Backup SQL Database
    Invoke-Sqlcmd -Query ”BACKUP DATABASE [DatabaseName] TO DISK = ’C:\Backup\BackupFile.bak'”
  17. Restore SQL Database
    Invoke-Sqlcmd -Query ”RESTORE DATABASE [DatabaseName] FROM DISK = ’C:\Backup\BackupFile.bak'”
  18. List Active Connections to SQL Server
    Invoke-Sqlcmd -Query ”SELECT * FROM sys.dm_exec_connections”
  19. Get Network Statistics for Interface
    Get-NetAdapterStatistics -Name ”Ethernet”
  20. Get IP Routing Table
    Get-NetRoute
  21. Display All Environment Variables
    Get-ChildItem Env:
  22. Create a New Virtual Machine in Hyper-V
    New-VM -Name ”NewVM” -MemoryStartupBytes 2GB -VHDPath ”C:\VMs\NewVM.vhdx” -Generation 2
  23. Start a Virtual Machine in Hyper-V
    Start-VM -Name ”NewVM”
  24. Stop a Virtual Machine in Hyper-V
    Stop-VM -Name ”NewVM”
  25. Get Virtual Machine Status in Hyper-V
    Get-VM -Name ”NewVM”
  26. Set Virtual Machine Memory
    Set-VM -Name ”NewVM” -MemoryStartupBytes 4GB
  27. Export Virtual Machine in Hyper-V
    Export-VM -Name ”NewVM” -Path ”C:\VMs\Backup”
  28. Import Virtual Machine in Hyper-V
    Import-VM -Path ”C:\VMs\Backup”
  29. Enable Windows Defender Antivirus
    Set-MpPreference -DisableRealtimeMonitoring $false
  30. Disable Windows Defender Antivirus
    Set-MpPreference -DisableRealtimeMonitoring $true
  31. Install Windows Feature via PowerShell
    Install-WindowsFeature -Name Web-Server
  32. Uninstall Windows Feature
    Uninstall-WindowsFeature -Name Web-Server
  33. Create a Scheduled Task
    New-ScheduledTaskTrigger -AtStartup | Register-ScheduledTask -Action ”C:\Path\to\script.ps1” -TaskName ”MyTask”
  34. Export Windows Firewall Rules to XML
    Export-WindowsFirewallRules -FilePath ”C:\FirewallRules.xml”
  35. Import Windows Firewall Rules from XML
    Import-WindowsFirewallRules -FilePath ”C:\FirewallRules.xml”
  36. Add an Exception to Windows Firewall
    New-NetFirewallRule -DisplayName ”Allow ICMP” -Protocol ICMPv4 -Direction Inbound -Action Allow
  37. Check Disk Health (SMART)
    Get-WmiObject -Class Win32_DiskDrive | Select-Object Model, Status
  38. View System Services and Start Modes
    Get-Service | Select-Object Name, StartType, Status
  39. Test Network Speed
    Test-Connection google.com -Count 10 | Measure-Object -Property ResponseTime -Minimum -Maximum -Average
  40. Automate File Download with PowerShell
    Invoke-WebRequest -Uri ”http://example.com/file.zip” -OutFile ”C:\file.zip”
  41. Backup Files to Network Share
    Copy-Item -Path ”C:\Data” -Destination ”\\NetworkShare\Backup” -Recurse
  42. Create a Custom PowerShell Module
    New-Module -ScriptBlock {function Get-MyCommand {Write-Host ”Hello”}} | Export-ModuleMember -Function Get-MyCommand
  43. Monitor Folder for Changes (File System Watcher)
    Register-WmiEvent -Class Win32_Directory -Action { Write-Host ”Change Detected!” }
  44. Send Email from PowerShell
    Send-MailMessage -To ”email@example.com” -From ”sender@example.com” -Subject ”Test” -Body ”Body of the message” -SmtpServer ”smtp.server.com”
  45. Create an IIS Website
    New-Website -Name ”TestWebsite” -Port 80 -PhysicalPath ”C:\Websites\Test” -ApplicationPool ”DefaultAppPool”
Upphovsrätt © 2025 NOAS IT. Alla rättigheter förbehålles. | SimClick av Catch Themes
NOAS IT
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.