Windows PowerShell Basic Commands running on Windows Server 2019

Basic PowerShell Commands for General Purpose running on Windows Server 2019 Datacenter Edition by VMware Workstation. 

OS basic verification:

To get the version of the PowerShell, use the following command:

"Get-host | select Version"

"$PSVersionTable" 

Windows Updates

Some modules are not available by default on the PowerShell. 
So you will need to manually download it. 
I downloaded the module PSWindowsUpdate 
which will enable me to update the OS from 
PowerShell:

"Get-Module PSWindowsUpdate"

List of services running:

"Get-Service"

Display available commands

This will display all commands that are available 
based on the modules that are loaded:

"Get-Command" [Press Tab] for autocorrect the spelling if needed

Get the process running on Windows Server:

"Get-Process" 

One of the first things you might want to do is to get the updates that need to be installed 
on the Operating System first which I did with the following command:

"Get-WindowsUpdateLog"

Search Get Help

Use this to search the help files. This is useful if you don’t know the 
command or want to see if one exists:

"Get-Help" *keyword*

Search Update Help 

Use this command to download module for Microsoft PowerShell Utilities:

"Update-Help" 

Get help for a command

Use this to get the help information for a command: 

"Get-Help command-name"

List All Available Modules

This will list all available modules on the computer:

"Get-Module -ListAvailable"

Get Execution Policy 

The Execution Policy helps protect you from scripts that you do not trust:

"Get-Executionpolicy"

Set Execution Policy to Unrestricted

Changing the execution policy might expose you to the security risks 
described in the about_Execution_Policies help topic:

"Set-Executionpolicy unrestricted"

Find New Modules:

Replace *ntfs* with the keyword you want to search for. This searches 
modules at https://www.powershellgallery.com/

"Find-Module *ntfs*"

Install a New Module

Installs modules from https://www.powershellgallery.com/

I found a module called NTFSSecurity, to install it. And I run this command:

"Install-Module NTFSSecurity" 

Networking

Finding the rules on the firewall:

"Get-NetFirewallRule"

IP configuration:

"Get-NetIPConfiguration"

To verify if IPv4 or IPv6 is enabled or not:

"Get-NetAdapterLso"

To get the routing table: 

"Get-NetRoute"

Disk Storage 

Get the disk space information:

"Get-WmiObject win32_logicaldisk"

Physical Hard disk Storage information:

"Get-PhysicalDisk"

Getting the used/free space:

"Get-PSDrive C | Select-Object Used, Free"

To install a module, you can search for it and install it directly:

"Find-Module -Name PendingReboot | Install-Module"

To get information which command to use for a pending reboot use:

"Get-Command -Module PendingReboot"

Getting help with commands arguments are pretty easy. Let’s say 
you want to know the possible arguments of the command
Get-Command, simply do:

"Get-Command -?"

Restart Remote Computers:

Restart-Computer -ComputerName "Server01", "Server02", 
"localhost"

Discovering Cmdlets and aliases looks like inside PowerShell:

"ls"
Directory: C:\ contents [All show you same results]

Directory Command:

"dir" 
Directory: C:\ contents [All show you same results]

"Get-ChildItem"
Directory: C:\ contents [All show you same results]

Getting Help for Set-VMware: 

"Get-Help set-vm"

Export the list of Services running on Windows Server 2019 
Datacenter Edition: 

"get-service | out-file c:\services.txt"

Using Powershell command to know about my Computer Name:

"$env:computername"

Using the PowerShell Command Rename-Computer Name:

"Rename-Computer -computername WIN-380VDOFU2K5 
-newname BIBEK-007"

Successfully Rename the name of my Computer Name: 

To verify check also at "Active Directory Users and Computers" 
& if needed type "sysdm.cpl" from Win+R. 

To Restart the computer with the help of Powershell Command:

"Restart-Computer" 

You can also find the list of updates installed on the machine using the following command:

"Get-Hotfix"


Comments

Post a Comment