Skip to content

PowerShell Commands for Windows Server 2016

Get-WindowsFeature – List of roles, features, and services (and Install State)

Install-WindowsFeature [service-name-here] -IncludeManagementTools – Installs the desired service with management tools

Get-WindowsFeature | where Installed – lists all roles, freautres that have been installed on server

Uninstall-WindowsFeature [featureName] -IncludeManagementTools – removes the desired service and managment tools

Set-NetFirewallRule DisplayGroup “Remote Event Log Management” -enabled True – allows remote management of a server

Get-Service -DisplayName Pr* – shows all services that have Pr at the beginning

Installing Roles and Feature – GUI

Install-WindowsFeature -ConfigurationFilePath [XMLscript.xml] – use to automate the installation of a role if has been done before and generated an XML file

Installing Roles and Feature – PowerShell

Get-WindowsFeature {| where installedState -eq Available– list of avilable roles and features

Install-WindowsFeature [RoleOrFeatureName] {-IncludeAllSubFeature -IncludeManagementTools -VHD [pathname] -ComputerName [name or IP]} – installed the named role. Separate with a space for multiple roles. Subfeatures are things below that assist the feature. Management tools help the admin run the feature. VHD allows you to mount the feature to an offline VHD. ComputerName allows you to install the feature on a remote computer.

Installing Roles and Feature – VHD with Disk Image Servicing and Management

dism /mount-wim /wimfile:[pathtoWimFile] /index:1 /mountdir:[pathToMountedImage] – mount the install image

dism /image:[pathToMountedImage] /{enable-feature, disable-feature, get-features} /featurename:[roleOrFeatureName] – install the desired role/feature

dism /unmount-wim /wimfile:[pathtoMountedImage] /commit – unmount add add the feature

Desired State Configuration

  • Make a script in the Intergreated Scripting Environemnet PowerShell
  • Create a management Object file by running the script
  • Run the cmdlet Start-DscConfiguration

Get-DscResources – lists the resources you can use with DSC

Remote Management

Adding Servers to Manage

Set-Item wswman:\localhost\client\TrustedHosts [remoteServerName] -Concatenate -Force – adds remote host to the local server’s list of trusted hosts – allows you to manage them

Enabling/Disabling Windows Remote Managment

winrm quickconfig -starts service and configs firewall

To initially start WinRM:

Enable-PSRemoting Enables WinRM

Disable-PSRemoting -Disables WinRM

Test-WSMan -ComputerName [computer] – Tests if WinRM is running on computer.

To Turn it on/off:

Configure-SMRemoting.exe -Get – displays current state of WinRM

Configure-SMRemoting.exe -Enable – turn it on

Configure-SMRemoting.exe -Disable – turn it off

Allow Firewall to Stop Working

Netsh advfirewall firewall set rule group=”COM+ Network Access” new enable =yes {[-r [remoteComputer]}

or

Set-NetFirewallRule -DisplayGroup “COM+ Network Access” -enabled True

Netsh advfirewall firewall set rule group=”Remote Event Log Management” new enable =yes {[-r [remoteComputer]}

or

Set-NetFirewallRule -DisplayGroup “Remote Event Log Management” -enabled True

Set-NetFirewallRule -DisplayGroup “Windows Firewall Remote Management” -enabled True – Allow the advanced firewall snap-in to go through on ServerCore, since it doesn’t have a COM+ Network Access Firewall

Managing Images with Powershell

Add-WdsDriverPackage -Architecture x64 {-ImageName [nameOfImage] -Name [nameOfDriverBeingAdded]} – Adds a driver package to a driver group or into a boot image.

Make Boot/Install Images (Un)Accessible to MDS Clients

Disable-WdsBootImage -Architecture x64 -ImageName [nameOfImageBeingDisabled] – makes the BOOT image unobtainable to WDS clients

Disable-WdsInstallImage -InstallImageName [nameOfImageBeingDisabled] – makes the INSTALL image obtainable to WDS clients

Enable-WdsBootImage -Architecture x64 -ImageName [nameOfImageBeingDisabled] – makes the BOOT image unobtainable to WDS clients

Enable-WdsInstallImage -InstallImageName [nameOfImageBeingDisabled] – makes the INSTALL image obtainable to WDS clients

Export/Import Boot/Install Images to MDS

Export-WdsBootImage -Architecture x64 -Destination [path] -ImageName “[desiredName]” – export BOOT image from WDS to a .wim file (Windows Image File)

Export-WdsInstallImage -Architecture x64 -Destination [path] -ImageName “[desiredName]” – export INSTALL image from WDS to a .wim file (Windows Image File)

Import-WdsBootImage -Path W:\images\StandSetup.wim -ImageName “[desiredName] – import BOOT image from .wim file to a WDS file (makes ready to use for WDS clients)

Import-WdsInstallImage -Path W:\images\StandSetup.wim -ImageName “[desiredName] – import INSTALL image from .wim file to a WDS file (makes ready to use for WDS clients)

Get WDS Boot/Install Image Properties

Get-WdsBootImage -Architecture x64 -ImageName “[desiredName]” – Lists properties of boot image

Get-WdsInstallImage -Architecture x64 -ImageName “[desiredName]” – Lists properties of boot image

Delete WDS Boot/Install Images

Remove-WdsBootImage -Architecture x64 -ImageName “[targetName]” – deletes the target BOOT image from WDS

Remove-WdsInstallImage -Architecture x64 -ImageName “[targetName]” – deletes the target INSTALL image from WDS

Change Properties of Boot/Install Images in WDS

Set-WdsBootImage -Architecture x64 -ImageName “Standard Setup Boot” {-Multicast -NewImageName [newName] [-NewDescription [description] [-DisplayOrder [indexOfImage]} – modifies properties of BOOT images

Set-WdsInstallImage -Architecture x64 -ImageName “Standard Setup Boot” {-Multicast -NewImageName [newName] [-NewDescription [description] [-DisplayOrder [indexOfImage]} – modifies properties of INSTALL images

Leave a Reply

Your email address will not be published. Required fields are marked *