- <
- .SYNOPSIS
- This script contains a function, EchoArgs, that returns a list of
- the arguments passed and their type. It is used to demonstrate
- the use of the --% operator when calling a function or cmdlet, a new
- feature in PowerShell v3.
- .DESCRIPTION
- The EchoArgs function takes the arguments passed, via $args, and
- displays each argument and its type. Then, this function is called
- first with a normal calling sequence and then using --%.
- .NOTES
- File Name : EchoArgs.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.
- .EXAMPLE
- Psh[Cookham8:C:\foo]>E:\PowerShellScriptLib\SERVER2012FEATURES\EchoArgs.ps1
- Calling Echoargs with 'fasdf $(LS) 2334 {asdf}'
- Argument [0]: [fasdf] Type:System.String
- Argument [1]: [System.Object[]] Type:System.Object[]
- Argument [2]: [2334] Type:System.Int32
- Argument [3]: [asdf] Type:System.Management.Automation.ScriptBlock
-
- Calling Echoargs with '--% asdf; {asfd}-a asdf'
- Argument [0]: [--%] Type:System.String
- Argument [1]: [asdf; $(ls) {asfd} - a asdf] Type:System.String
-
-
-
- Function EchoArgs {
-
- For ($i = 0; $i -ilt $Args.count; $i ++) {
- "Argument [{0}]: [{1}] Type:{2}" -f $I, $args[$i],$($args[$i].GetType().FullName)
- }
- }
-
-
- "Calling Echoargs with 'fasdf `$(LS) 2334 {asdf}'"
- Echoargs fasdf $(ls) 2334 {asdf}
- "";"Calling Echoargs with '--% asdf; {asfd}-a asdf'"
- Echoargs --% asdf; $(ls) {asfd} - a asdf
- <
- .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 {
-
-
-
-
- [Cmdletbinding()]
- Param()
-
-
- Write-Verbose "Removing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra"
- Uninstall-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra
-
-
- 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
-
-
- Write-Verbose "Restarting the computer - please be patient"
- Restart-Computer
- }
- <
- .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 {
-
-
- [Cmdletbinding()]
- Param()
-
- 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
-
- 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
-
- Write-Verbose "Finished installation, now rebooting"
- Restart-Computer
- }
- <
- .SYNOPSIS
- This script demonstrates setting default values for Local Hyper-V host.
- .DESCRIPTION
- This script imports the Hyper-V module then uses it
- to set certain default values for this hyper-V Host
- .NOTES
- File Name : Set-HyperVHostDefault.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0 and Windows 8/Server 2012
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Left as an exercise for the reader
-
-
-
-
-
- Import-Module Hyper-V
-
- Write-Verbose "$((gcm -module hyper-v).Count) cmdlets imported in Hyper-V Module"
-
-
- $parm = @{}
-
-
- $parm += @{ComputerName = "Win8.Cookham.Net"}
-
-
- $parm += @{VirtualMachinePath = "E:\hyperv"}
-
-
- $parm += @{VirtualHardDiskPath = "E:\hyperv"}
-
-
- Write-Verbose "Setting parameters as follows:";$parm
- Set-VmHost @parm
-
-
-
- Get-VMHost
-
-
- <
- .SYNOPSIS
- This script demonstrates creating a Hyper-V Switch
- .DESCRIPTION
- This script imports the Hyper-V module then uses it
- to create an Internal Switch for use in future provisioning.
- .NOTES
- File Name : New-InternalSwitch.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0 and Windows 8/Server 2012
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- C:\foo\> .New-InternalSwitch.ps1
- VERBOSE: New-InternalSwitch will create a new virtual network.
- Name SwitchType NetAdapterInterfaceDescription
- ---- ---------- ------------------------------
- Internal Internal
-
-
- Import-Module Hyper-V
- Try {New-VMSwitch -Name Internal -SwitchType Internal -ComputerName LocalHost -Verbose}
- Catch { "Failed to create switch"; $error[0] }
-