Wednesday 3 October 2012

Get-GuiMode.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script gets the current GUI mode of a Windows 
  4.     Server 2012 system, including current display resolution. 
  5. .DESCRIPTION 
  6.     This script creates a custom object, then populates it 
  7.     with the current mode (Server Core, MinShell, Full Shell) 
  8.     and with the current resolution (resolution plus h/w). The 
  9.     display information object is then returned. 
  10. .NOTES 
  11.     File Name  : Get-GuiMode.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 3.0  
  14.                  Windows Server 2012 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18. .EXAMPLE 
  19.     Psh>  ./Get-GuiMode 
  20.     ComputerName : S1 
  21.     ServerCore   : True 
  22.     FullServer   : False 
  23.     MinShell     : False 
  24.     Resolution   : 1024x768 
  25.     Height       : 768 
  26.     Width        : 1024 
  27.  
  28. #> 
  29.  
  30.  
  31. Function Get-GUIMode { 
  32.  
  33. # Create a new object to return 
  34. $guimode = new-object psobject 
  35.  
  36. # Add ComputerName to the object 
  37. $guimode |Add-Member -MemberType NoteProperty -Name ComputerName -Value $(hostname) 
  38.  
  39.  
  40. # now determine what's installed 
  41. $sgs  = (Get-WindowsFeature Server-Gui-Shell).Installed 
  42. $mif  = (Get-WindowsFeature Server-Gui-Mgmt-Infra).Installed 
  43.  
  44. If (!$sgs -and !$mif# True Server Core  
  45.   { 
  46.     $guimode |Add-Member -MemberType NoteProperty -Name ServerCore -Value $True 
  47.     $guimode |Add-Member -MemberType NoteProperty -Name FullServer -Value $False 
  48.     $guimode |Add-Member -MemberType NoteProperty -Name MinShell   -Value $False 
  49.   } 
  50. Elseif ($sgs -and !$mif) # MinShell 
  51.   { 
  52.     $guimode |Add-Member -MemberType NoteProperty -Name ServerCore -Value $False 
  53.     $guimode |Add-Member -MemberType NoteProperty -Name FullServer -Value $False 
  54.     $guimode |Add-Member -MemberType NoteProperty -Name MinShell   -Value $True 
  55.   } 
  56. Elseif ($sgs -and $mif
  57.   { 
  58.     $guimode |Add-Member -MemberType NoteProperty -Name ServerCore -Value $False 
  59.     $guimode |Add-Member -MemberType NoteProperty -Name FullServer -Value $True 
  60.     $guimode |Add-Member -MemberType NoteProperty -Name MinShell   -Value $False 
  61.   } 
  62.  
  63. # now resolution 
  64. If ($rx=get-command Get-DisplayResolution) { 
  65.   $res  = (Get-DisplayResolution)[0] 
  66.   $reslen = $res.length 
  67.   $r = [string]"" 
  68.   for ($i = 0; $i -lt $reslen; $i++) 
  69.    {  
  70.      If ($res.substring($i,1) -ne "") { $r += $res.substring($i,1) } 
  71.    } 
  72.  
  73.     
  74.   $guimode |Add-Member -MemberType NoteProperty -Name Resolution -Value $r 
  75.  
  76.   $h = $r.split("x")[1]  # height 
  77.   $w = $r.split("x")[0]  #  
  78.    
  79.   $guimode |Add-Member -MemberType NoteProperty -Name Height -Value $h 
  80.   $guimode |Add-Member -MemberType NoteProperty -Name Width  -Value $w 
  81.  
  82. # Ok - squirt out what we have! 
  83. $guimode 
  84.  
  85. # Here Test it out 
  86. Get-GUiMode 

3 comments:

rose99 said...

I feel pretty happy to have discovered your webpages and look forward to tons of more pleasurable times reading here. Thanks a lot once again for a lot of things.
power drive systems - replacement parts

Robin Meuré said...

Thanks for this script, I rewrote it a little to this:

$sgs = (Get-WindowsFeature Server-Gui-Shell).Installed
$mif = (Get-WindowsFeature Server-Gui-Mgmt-Infra).Installed

new-object PSObject -Property @{
ComputerName = $hostname
FullServer = ($sgs -and $mif)
MinShell =($sgs -and !$mif)
ServerCore = (!$sgs -and !$mif)
}

Robin Meuré said...

Thanks! I rewrote to this :)

$sgs = (Get-WindowsFeature Server-Gui-Shell).Installed
$mif = (Get-WindowsFeature Server-Gui-Mgmt-Infra).Installed

new-object PSObject -Property @{
ComputerName = $hostname
FullServer = ($sgs -and $mif)
MinShell =($sgs -and !$mif)
ServerCore = (!$sgs -and !$mif)
}