- <#
- .SYNOPSIS
- This script gets the current GUI mode of a Windows
- Server 2012 system, including current display resolution.
- .DESCRIPTION
- This script creates a custom object, then populates it
- with the current mode (Server Core, MinShell, Full Shell)
- and with the current resolution (resolution plus h/w). The
- display information object is then returned.
- .NOTES
- File Name : Get-GuiMode.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0
- Windows Server 2012
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Psh> ./Get-GuiMode
- ComputerName : S1
- ServerCore : True
- FullServer : False
- MinShell : False
- Resolution : 1024x768
- Height : 768
- Width : 1024
- #>
- Function Get-GUIMode {
- # Create a new object to return
- $guimode = new-object psobject
- # Add ComputerName to the object
- $guimode |Add-Member -MemberType NoteProperty -Name ComputerName -Value $(hostname)
- # now determine what's installed
- $sgs = (Get-WindowsFeature Server-Gui-Shell).Installed
- $mif = (Get-WindowsFeature Server-Gui-Mgmt-Infra).Installed
- If (!$sgs -and !$mif) # True Server Core
- {
- $guimode |Add-Member -MemberType NoteProperty -Name ServerCore -Value $True
- $guimode |Add-Member -MemberType NoteProperty -Name FullServer -Value $False
- $guimode |Add-Member -MemberType NoteProperty -Name MinShell -Value $False
- }
- Elseif ($sgs -and !$mif) # MinShell
- {
- $guimode |Add-Member -MemberType NoteProperty -Name ServerCore -Value $False
- $guimode |Add-Member -MemberType NoteProperty -Name FullServer -Value $False
- $guimode |Add-Member -MemberType NoteProperty -Name MinShell -Value $True
- }
- Elseif ($sgs -and $mif)
- {
- $guimode |Add-Member -MemberType NoteProperty -Name ServerCore -Value $False
- $guimode |Add-Member -MemberType NoteProperty -Name FullServer -Value $True
- $guimode |Add-Member -MemberType NoteProperty -Name MinShell -Value $False
- }
- # now resolution
- If ($rx=get-command Get-DisplayResolution) {
- $res = (Get-DisplayResolution)[0]
- $reslen = $res.length
- $r = [string]""
- for ($i = 0; $i -lt $reslen; $i++)
- {
- If ($res.substring($i,1) -ne "") { $r += $res.substring($i,1) }
- }
- $guimode |Add-Member -MemberType NoteProperty -Name Resolution -Value $r
- $h = $r.split("x")[1] # height
- $w = $r.split("x")[0] #
- $guimode |Add-Member -MemberType NoteProperty -Name Height -Value $h
- $guimode |Add-Member -MemberType NoteProperty -Name Width -Value $w
- }
- # Ok - squirt out what we have!
- $guimode
- }
- # Here Test it out
- Get-GUiMode
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Showing posts with label ServerCore. Show all posts
Showing posts with label ServerCore. Show all posts
Wednesday, 3 October 2012
Get-GuiMode.ps1
Labels:
powershell,
PowerShell v3,
Server2012,
ServerCore
Set-PowerShellAsShell
- <#
- .Synopsis
- Creates a function to set PowerShell as GUI in Server 2012
- .DESCRIPTION
- The function in this script sets PowerShell as the
- default shell in Server 2012. When the server is rebooted,
- it runs PowerShell.exe by default. When PowerShell starts, it
- displays the $PSVersionTable variable.
- .NOTES
- File Name : Set-PowerShellAsGui.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : Server 2012
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Left as an exercise to the reader
- #>
- Function Set-PowerShellAsShell {
- [CmdletBinding()]
- Param (
- [switch] $Reboot = $false
- )
- # Create Registry Path variable
- $RegPath = "Microsoft.PowerShell.Core\Registry::"
- $RegPath += "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\"
- $RegPath += "Windows NT\CurrentVersion\winlogon"
- # Create splatted parameter hash table
- $parm = @{Path = $regpath} # key
- $parm += @{Name = 'Shell'} # value name
- $parm += @{Value = 'PowerShell.exe –NoExit
-Command "$psversiontable"'} # value’s value - # Set Registry value entry
- Set-ItemProperty @parm
- # And restart to see PowerShell
- if ($Reboot) {Restart-Computer -confirm}
- }
Labels:
powershell,
PowerShell scripts,
PowerShell V2,
PowerShell v3,
Server,
Server2012,
ServerCore
Tuesday, 18 September 2012
Disable-Gui.ps1
- <#
- .SYNOPSIS
- This script defines a function, Disable-Gui which
- disables the GUI on Windows Server 2012 Server Core
- .DESCRIPTION
- The Disable-GUI function enables the GUI in Server 2012
- Server Core by Removing two windows features. The
- script add a Shell setting to ensure that when
- Server 2012 restarts, it starts with PowerShell.
- .NOTES
- File Name : Disable-GUI.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0 and Windows Server 2012.
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Psh> Disable-GUI -Verbose
- Removing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra
- Setting Shell Registry setting to PowerShell
- Restarting the computer - please be patient
- < after reboot, full GUI is added >
- #>
- Function Disable-GUI {
- # No parameters - but maybe later
- # Turn on CmdletBinding to enable -Verbose
- [Cmdletbinding()]
- Param()
- # Remove features from main Server core and downgrade GUI to Server Core
- Write-Verbose "Removing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra"
- Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
- # Add in PowerShell as the shell
- Write-Verbose "Setting Shell Registry setting to PowerShell"
- $RegPath = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon"
- Set-ItemProperty -Path $RegPath -Name Shell -Value 'PowerShell.exe -noExit -Command "$psversiontable"' -Force
- # Now restart the system
- Write-Verbose "Restarting the computer - please be patient"
- Restart-Computer
- }
Labels:
PowerShell v3,
Server2012,
ServerCore
Enable-GUI.ps1
- <#
- .SYNOPSIS
- This script defines a function, Enable-Gui which
- enables the GUI on Windows Server 2012 Server Core
- .DESCRIPTION
- The Enable-GUI function enables the Gui in Server 2012
- Server Core by adding in two windows features. The
- script removes any Shell setting to ensure that when
- Server 2012 restarts, it starts with the full Desktop.
- .NOTES
- File Name : Enable-GUI.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0 and Windows Server 2012.
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Psh> Enable-GUI -Verbose
- Installing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra
- Removing Shell Registry Setting
- Finished installation, now rebooting
- < after reboot, full GUI is added >
- #>
- Function Enable-GUI {
- # No parameters - but maybe later
- # Turn on CmdletBinding to enable -Verbose
- [Cmdletbinding()]
- Param()
- # Install the GUI
- Write-Verbose "Installing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra"
- Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra -Source d:\sources\sxs
- # Remove the Setting For Shell to force back to CMD.EXE
- Write-Verbose 'Removing Shell Registry Setting'
- $RegPath = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon"
- Remove-ItemProperty -Confirm -Path $RegPath -Name Shell -ErrorAction SilentlyContinue
- # And reboot the system
- Write-Verbose "Finished installation, now rebooting"
- Restart-Computer
- }
Labels:
PowerShell v3,
Server2012,
ServerCore
Thursday, 5 July 2012
Manage-ServerCoreGui.ps1
- <#
- .Synopsis
- This file contains two simple functions to manage the GUI
- in Server Core Windows Server 2012.
- .DESCRIPTION
- There are two functions: Enable-ServerCoreGui that enables
- the GUI in a server core installation. Diable-ServerCoreGuI
- disables the GUI and returns the installation to
- traditional Server Core.
- Enable-ServerCoreGui also checks to see if some or all
- parts are already installed andwarns accordingly.
- .EXAMPLE
- c:\foo> Enable-ServerCoreGui
- This enables the GUI and reboots the Server into FUll GUI mode.
- .EXAMPLE
- c:\foo> Disable-ServerCoreGui
- This disables the GUI and reboots the Server back to Server Core mode.
- #>
- Function Enable-ServerCoreGui {
- # Import the module
- Import-Module -Name DISM -ErrorAction Stop
- # is it already enabled??
- if ((Get-WindowsOptionalfeature -online -Feature ServerCore-FullServer).state -eq 'Enabled'){
- "Servercore-FullServer is already enabled"
- }
- if ((Get-WindowsOptionalfeature -online -Feature Server-GUI-Shell).state -eq 'Enabled'){
- "Server-GUI Shell is already enabled"
- }
- if ((Get-WindowsOptionalfeature -online -Feature Server-Gui-Mgmt).state -eq 'Enabled'){
- "Server-Gui-Mgmt is already enabled"
- }
- # Enable the features needed to add the GUI
- Enable-WindowsOptionalFeature –Online -NoRestart `
- -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt
- # So Restart the computer
- Restart-computer
- }
- Function Disable-ServerCoreGui {
- # Import the module
- Import-Module -Name DISM -ErrorAction Stop
- # Disable all the features needed to add the GUI
- # if any are already disabled, oh well - they're still disabled.
- Disable-WindowsOptionalFeature –Online -NoRestart `
- -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt
- # Finally Restart the computer
- Restart-computer
- }
Subscribe to:
Posts (Atom)