- <#
- .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.
Wednesday, 3 October 2012
Get-GuiMode.ps1
Labels:
powershell,
PowerShell v3,
Server2012,
ServerCore
Subscribe to:
Post Comments (Atom)
3 comments:
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
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)
}
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)
}
Post a Comment