Advertisement
hjaltiatlason

Powershell commands - Useful

Jan 9th, 2021 (edited)
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #How old is your Windows install?
  2. gwmi Win32_OperatingSystem | select InstallDate
  3.  
  4. #Spit out all the printers
  5. gwmi win32_printer | select Name, Portname, Default
  6.  
  7. #Get Serial number/service tag
  8. gwmi win32_bios | select serialnumber
  9.  
  10. #Shut down immediately, avoiding windows update:
  11. shutdown /s /t 0
  12.  
  13. #Restart when you're logged in with RDP and the shutdown / restart commands are hidden:
  14. shutdown /r /t 0
  15.  
  16. #Restart service
  17. restart-service servicename
  18.  
  19. #List of all installed applications on a Windows device + all installed Windows Update files (KB)
  20. Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize
  21.  
  22.  
  23. #This script will look for the host.bak file in C:\
  24. Get-Childitem -Path C:\ -Recurse -Filter hosts.bak -ErrorAction SilentlyContinue
  25.  
  26.  
  27. #Find Last Bootup Time
  28. Get-WmiObject win32_operatingsystem |select @{Name="Last Boot Time"; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}}, PSComputerName
  29.  
  30. #Find Your Public IP Address
  31. (Invoke-RestMethod ipinfo.io/json).ip
  32.  
  33.  
  34. #ipconfig /all equivalent gip is short for Get-NetIPConfiguration.
  35. gip
  36.  
  37.  
  38. #Show network adaptors
  39. get-netadapter
  40.  
  41. #Restart remote computer
  42. restart-computer -computername [computer]
  43.  
  44. #Sync Ad Changes without waiting for the next sync cycle before the minimum time between sync via Azure AD connect
  45. Start-ADSyncSyncCycle -PolicyType Delta
  46.  
  47.  
  48. #To display the detailed information about all available user attributes, run this command:
  49. Get-ADUser -identity tuser -properties *
  50.  
  51. #Display all enabled AD users with First Name and Lastname
  52. Get-ADUser -Filter "(surname -like '*') -And (givenname -like '*') -and (enabled -eq '$true')" | ft Givenname,surname
  53.  
  54. #Get AD groups a AD user is member of
  55. Get-ADPrincipalGroupMembership username | ft name
  56.  
  57.  
  58. #Export all AD Objects and all of their available attributes
  59. csvde -f output.csv
  60.  
  61. #Check for accounts that don't have password expiry set
  62. Get-ADUser -Filter 'useraccountcontrol -band 65536' -Properties useraccountcontrol | export-csv C:\Windows\Temp\U-DONT_EXPIRE_PASSWORD.csv  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement