- <#
- .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
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
Monday, 1 October 2012
Show-FolderCreation.ps1
- <#
- .SYNOPSIS
- This example shows how to create a new directory and
- subdirectory, and then delete only the subdirectory.
- .DESCRIPTION
- This sample is a re-write of an MSDN Sample,
- but in PowerShell. The sample firsts creates then removes
- a folder then looks to see what is left. The target
- folder is removed, but intermediate folders remain.
- .NOTES
- File Name : Show-FolderCreation.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/62t64db3.aspx
- .EXAMPLE
- Psh> Show-FolderCreation.ps1
- Created: C:\NewDirectory\NewSubDirectory
- Deleted: C:\NewDirectory\NewSubDirectory
- Top-level directory exists: True
- Sub-directory exists : False
- #>
- [CmdletBinding()]
- Param (
- $Path = "C:\NewDirectory\NewSubDirectory"
- )
- Try
- {
- # Create then remove directory
- $result = [System.IO.Directory]::CreateDirectory($Path)
- "Created: $path"
- [System.IO.Directory]::Delete($Path)
- "Deleted: $path"
- # Check existance for top and sub dirs then display results
- $directoryExists = [System.Io.Directory]::Exists("C:\NewDirectory")
- $subDirectoryExists = [System.Io.Directory]::Exists($Path)
- "Top-level directory exists: $directoryExists"
- "Sub-directory exists : $subDirectoryExists"
- }
- Catch
- {
- "The process failed: {0}" -f $($error[0].Message)
- }
Subscribe to:
Posts (Atom)