Rootctl

Windows

List
PowerShell Commands





KB PoweShell



PowerShell Registry check for NET Framework Version:
----------------------------------------------------
gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | gp -name Version -EA 0 | where { $_.PSChildName -match '^(?!S)\p{L}'} | select PSChildName, Version





Software Documentation :
----------------------------------------------------------------------
Remove all TeamViewer installs, you can change this to other software instead of TeamViewer but not all support this uninstall method, and make sure to test.
Get-WmiObject -Class Win32_Product -Filter "Vendor LIKE 'TeamViewer' " | Foreach { ($_).uninstall() }

----------------------------------------------------------------------

List all Installed 32bit software:
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate

----------------------------------------------------------------------

List all Installed 64bit software:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Where-Object Displayname -notlike ""

----------------------------------------------------------------------
List of all installed applications on a Windows device
------------------------------------------------------
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table -AutoSize
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


List all installed software: (all 3 lines)
$Software_List = @(); $Software_List += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
| Select-Object DisplayName, DisplayVersion, Publisher, InstallDate; $Software_List += Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
| Select-Object DisplayName, DisplayVersion, Publisher, InstallDate ; $Software_List

----------------------------------------------------------------------

List all installed AppXpackages for all Users
Get-AppxPackage –AllUsers
----------------------------------------------------------------------

----------------------------------------------------------------------
Local Computer Commands :
----------------------------------------------------------------------


List all local user accounts:
Get-LocalUser

----------------------------------------------------------------------

Get useful info on Computer:
get-ComputerInfo

----------------------------------------------------------------------

Same as above but with less details:
Get-ComputerInfo CsName,WindowsProductName,CsDomain,CsProcessors,LogonServer,OsVersion,BiosReleaseDate

----------------------------------------------------------------------

Download a file from a known URL to C:\temp\ and Rename it:
Invoke-WebRequest 'https://www.dropbox.com/download?os=win' -OutFile 'c:\temp\DropboxInstaller.exe'

----------------------------------------------------------------------

Empty Recycling Bin for C:
Clear-RecycleBin -force -driveletter C

----------------------------------------------------------------------

List Important Computer Information:
Get-computerinfo

----------------------------------------------------------------------

Get printer information:
Get-Printer

----------------------------------------------------------------------

Rename a computer and restart it:
Rename-Computer -newname DESKTOPNAMEHERE -Restart

----------------------------------------------------------------------

Restart the Print Spoolter Service:
Restart-Service -Name Spooler

----------------------------------------------------------------------

Restart a computer or shut it down
Restart-Computer
Stop-Computer

----------------------------------------------------------------------

Force an immediate restart:
Restart-Computer -Force

----------------------------------------------------------------------

List all processes that contain a specific word.
Get-process | where-object name -like "*word*"
----------------------------------------------------------------------

Stop all process that contain a specific work (be careful with this command):
Get-process | where-object name -like "*word*" | stop-process
Strongly recommend you run the command without the ‘| stop-process’ part first to confirm what will be stopped.

----------------------------------------------------------------------

Find all file paths longer than 220 characters in current folder (Use set-location (or ‘cd’) to select the folder first)
(Get-Childitem -Recurse).fullname | Where-Object length -gt 220
----------------------------------------------------------------------

----------------------------------------------------------------------
Event log commands :
----------------------------------------------------------------------
Find reason for unexpected shutdown on a server
Get-EventLog -LogName system -Source user32 | Select-Object TimeGenerated, Message | Sort-Object message

----------------------------------------------------------------------

Get the last 100 events in the system log
Get-EventLog -LogName system -Newest 100
----------------------------------------------------------------------

----------------------------------------------------------------------
Networking Commands:
----------------------------------------------------------------------

Test basic connectivity to a device or the internet
Test-connection google.com
Test-connection 10.1.1.1

----------------------------------------------------------------------

Clear DNS Cache
Clear-DnsClientCache

----------------------------------------------------------------------

Check if domain computers domain trust is working, and repair it.
Test-ComputerSecureChannel

----------------------------------------------------------------------

Repair domain computers domain trust.
Test-ComputerSecureChannel -Repair

----------------------------------------------------------------------

Check if an outbound port is open
Test-NetConnection -Port 80

Test-netconnection -port 443 -computername ...
----------------------------------------------------------------------

----------------------------------------------------------------------
Getting the Output
----------------------------------------------------------------------
Put the output into the clipboard
| Clip
E.g. get-printer | clip

----------------------------------------------------------------------

Format the output as a List or a table
| Format-List
| Format-Table
e.g. Get-Printers | Format-List

----------------------------------------------------------------------

Save output to a file
| Out-FIle C:\temp\PowershellOutput.txt
e.g. Get-Service | Out-FIle C:\temp\PowershellOutput.txt

----------------------------------------------------------------------


View the Output in filterable and sortable list
| Out-Gridview
e.g. Get-Service | Out-Gridview
----------------------------------------------------------------------


To export all roles to a .CSV file and then use it on another server use the line below :
---------------------------------------------------------------------------------------
Get-WindowsFeature | where{$_.Installed -eq $True} | select name | Export-Csv C:\scripts\Roles.csv -NoTypeInformation -Verbose



Use the .CSV file to install a new Server with exactly the same roles and features :
----------------------------------------------------------------------------------
Import-Csv C:\scripts\Roles.csv | foreach{Add-WindowsFeature $_.name }



Importing and Exporting Windows Features with PowerShell :
---------------------------------------------------------
Import-Module ServerManager





Windows features xml or text file - from a reference server:
---------------------------------------------------------------------------------
Get-WindowsFeature | ? { $_.Installed } | Export-Clixml .\Features.xml

OR

Get-WindowsFeature | ? { $_.Installed } | Select Name | ForEach-Object { $_.Name } | Out-File .\Features.txt


To install Feature from above export:
----------------------------------------------------
$(Import-Clixml .\Features.xml) | Add-WindowsFeature
OR
$(Get-Content .\Features.txt) | Add-WindowsFeature


If prefer the TXT file and a Sort for an easy way to compare the files to easily compare of two Servers:
--------------------------------------------------------------------------------------------------------
Export:
-------
Import-Module ServerManager
Get-WindowsFeature | ? { $_.Installed } | Sort-Object Name | Select Name | ForEach-Object { $_.Name } | Out-File .\Features.txt
Out-File .\Features.txt
-----------------------

Import:
--------
Import-Module ServerManager
$(Get-Content .\Features.txt) | Add-WindowsFeature
-----------------------------------------------------


Importing AND Exporting Windows Features PowerShell :
------------------------------------------------------------------------------------------------------------------------------------------
Import-Module ServerManager


Create your windows features xml or text file with the one of the following commands from a reference server:
------------------------------------------------------------------------------------------------------------------------------------------
Get-WindowsFeature | ? { $_.Installed } | Export-Clixml .\Features.xml
OR
Get-WindowsFeature | ? { $_.Installed } | Select Name | ForEach-Object { $_.Name } | Out-File .\Features.txt


To install these features:
------------------------------------------------------------------------------------------------------------------------------------------
$(Import-Clixml .\Features.xml) | Add-WindowsFeature
OR
$(Get-Content .\Features.txt) | Add-WindowsFeature


If prefering the TXT file and a Sort for an easy way to compare the files to easily compare of two servers. Therefore my final scripts Export:
------------------------------------------------------------------------------------------------------------------------------------------
Import-Module ServerManager
Get-WindowsFeature | ? { $_.Installed } | Sort-Object Name | Select Name | ForEach-Object { $_.Name } | Out-File .\Features.txt


Import:
------------------------------------------------------------------------------------------------------------------------------------------
Import-Module ServerManager $(Get-Content .\Features.txt) | Add-WindowsFeature
OR:
Get-WindowsFeature | Where-Object {$_.InstallState -eq 'Installed'}

WMIC
Find Computer Model Number in Windows
------------------------------------------------------------
WMIC CSPRODUCT GET NAME

Find Computer Serial Number in Windows
---------------------------------------------------------
WMIC BIOS GET SERIALNUMBER


More WMIC handy Command:
---------------------------------------------------------
WMIC OS get Caption,CSDVersion,OSArchitecture,Version

WMIC BIOS get Manufacturer,Name,SMBIOSBIOSVersion,Version

WMIC CPU get Name,NumberOfCores,NumberOfLogicalProcessors

WMIC MEMPHYSICAL get MaxCapacity

WMIC MEMORYCHIP get Capacity,DeviceLocator,PartNumber,Tag

WMIC NIC get Description,MACAddress,NetEnabled,Speed

WMIC DISKDRIVE get InterfaceType,Name,Size,Status

WMIC USERACCOUNT get Caption,Name,PasswordRequired,Status

WMIC path win32_physicalmedia get SerialNumber

------------Serial Key form Windows 10 ------------
WMIC path SoftwareLicensingService get OA3xOriginalProductKey



.