rss logo

My PowerShell Commands List

Some PowerShell commands that I put here to remember.

Active Directory

  • Install Active Directory services
PS C:\ > Install-WindowsFeature AD-domain-services -Restart -IncludeManagementTools
PS C:\ > Import-Module ADDSDeployment
PS C:\ > Install-AddsForest
  • Install RSAT for Active Directory tools
PS C:\ > Install-WindowsFeature RSAT-ADDS
  • Join Domain
PS C:\ > $OU = "OU=Servers,DC=shebangthedolphins,DC=net"
PS C:\ > $Domain = "shebangthedolphins.net"
PS C:\ > $Cred = "shebangthedolphins.net\administrator"
PS C:\ > Add-Computer -DomainName $Domain -OUPath $OU -Credential $Cred -Restart -Force

General

  • Copy Files
PS C:\ > Copy-Item C:\*.ini -Destination E:\Temp\
  • Move Files
PS C:\ > Move-Item C:\*.txt -Destination E:\Temp\
  • Set Time
PS C:\ > Set-Date -date "12/7/2017 3:57 PM"
  • Set last write time
PS C:\ > $a = Get-Item '.\Downloads\My_File.txt'
PS C:\ > $a.LastWriteTime = "06/25/2016 8:00 AM"
  • List Windows Feature
PS C:\ > Get-WindowsFeature Hyper-V*
  • Install Windows Feature
PS C:\ > Install-WindowsFeature Hyper-V -Restart -IncludeManagementTools
  • Get modules list
PS C:\ > Get-Module
  • List all commands for a specific Module
PS C:\ > Get-Command -Module Hyper-V
  • Change Hostname
PS C:\ > Rename-Computer NewName -Restart
  • List installed programs and export to csv file :
PS C:\ > Get-WmiObject win32_product | Select-Object -Property Name,Version | Export-Csv -Path c:\My_Programs_List.csv
  • List running services and export to csv file :
PS C:\ > Get-Service | Where-Object { $_.Status -eq "Running" } | Select-Object Status,Name,DisplayName | Export-Csv c:\Services_List.csv

Network

  • Get Network Informations :
PS C:\ > Get-NetIPAddress
PS C:\ > Get-NetIPConfiguration
  • Get Network Interfaces :
PS C:\ > Get-NetIPInterface
  • Set Network Parameters :
PS C:\ > New-NetIPAddress -InterfaceAlias "InterfaceAlias" -IPAddress 192.168.1.10 -PrefixLength 24 -DefaultGateway 192.168.1.254 -AddressFamily IPv4
PS C:\ > Set-DnsClientServerAddress -InterfaceAlias "InterfaceAlias" -ServerAddresses 192.168.1.254
  • Remove Network Parameters :
PS C:\ > Remove-NetIPAddress -InterfaceAlias "InterfaceAlias"
  • Remove default gateway also :
PS C:\ > Remove-NetIPAddress -InterfaceAlias "InterfaceAlias" -DefaultGateway 192.168.1.254
  • Manage Network Connection Profile (Private, Public and DomainAuthenticated) :
PS C:\ > Get-NetConnectionProfile
PS C:\ > Set-NetConnectionProfile -InterfaceAlias Ethernet2 -NetworkCategory private
PS C:\ > Set-NetConnectionProfile -InterfaceIndex 10 -NetworkCategory private
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address