Showing posts with label Hyper-V. Show all posts
Showing posts with label Hyper-V. Show all posts

Wednesday, 23 January 2013

Configure-DC1-1.ps1

  1. # Configure-DC1-1.ps1
  2. # Converts Server to DC
  3. # Version 1.0.0 - 14 Jan 2013
  4. # See http://tfl09.blogspot.com for more details
  5. # Config script block
  6. $conf = {
  7. # Install the AD - the reboot is or should be automagic
  8. Install-Windowsfeature AD-Domain-Services -IncludeManagementTools
  9. # Now install the AD to DC1
  10. $PasswordSS = ConvertTo-SecureString -string 'Pa$$w0rd' -AsPlainText -Force
  11. Install-ADDSForest -DomainName Reskit.Org -SafeModeAdministratorPassword $PasswordSS -force -InstallDNS -DomainMode Win2012 -ForestMode Win2012
  12. }
  13. # Here is start of script
  14. $Username = "DC1\administrator"
  15. $PasswordSS = ConvertTo-SecureString 'Pa$$w0rd' -AsPlainText -Force
  16. $Creddc1 = New-Object system.management.Automation.PSCredential $username,$PasswordSS
  17. # First, run a simple script block to check that the server is actually running and is the one we think it is
  18. Invoke-Command -ComputerName DC1 -ScriptBlock { ipconfig;hostname} -Credential $Creddc1 -verbose
  19. Pause
  20. # Now add create our forest/domain/dc
  21. Invoke-Command -ComputerName DC1 -Scriptblock $conf -Credential $Creddc1 -verbose
Technorati Tags: ,,,

Sunday, 16 September 2012

Set-HyperVHostDefault.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates setting default values for Local Hyper-V host. 
  4. .DESCRIPTION 
  5.     This script imports the Hyper-V module then uses it 
  6.     to set certain default values for this hyper-V Host 
  7. .NOTES 
  8.     File Name  : Set-HyperVHostDefault.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 3.0 and Windows 8/Server 2012 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14. .EXAMPLE 
  15.    Left as an exercise for the reader 
  16.     
  17. #> 
  18.  
  19.  
  20. # Import Hyper-V Module 
  21. Import-Module Hyper-V 
  22.  
  23. Write-Verbose "$((gcm -module hyper-v).Count) cmdlets imported in Hyper-V Module" 
  24.  
  25. # Create $parm hash table! 
  26. $parm = @{} 
  27.  
  28. # Specify the Computername 
  29. $parm += @{ComputerName = "Win8.Cookham.Net"
  30.  
  31. # Specify the Hard Disk Path 
  32. $parm += @{VirtualMachinePath = "E:\hyperv"
  33.  
  34. # Specify the VHD Disk Path 
  35. $parm += @{VirtualHardDiskPath = "E:\hyperv"
  36.  
  37. # Set the VM host accordingly 
  38. Write-Verbose "Setting parameters as follows:";$parm 
  39. Set-VmHost @parm 
  40.  
  41. # And Display Details 
  42.  
  43. Get-VMHost 
  44.  
  45. # End Set-HyperVHostDefaults 

New-InternalSwitch.ps1

  1. <#
  2. .SYNOPSIS
  3.     This script demonstrates creating a Hyper-V Switch
  4. .DESCRIPTION
  5.     This script imports the Hyper-V module then uses it
  6.     to create an Internal Switch for use in future provisioning.
  7. .NOTES
  8.     File Name : New-InternalSwitch.ps1
  9.     Author : Thomas Lee - tfl@psp.co.uk
  10.     Requires : PowerShell Version 3.0 and Windows 8/Server 2012
  11. .LINK
  12.     This script posted to:
  13.     http://www.pshscripts.blogspot.com
  14. .EXAMPLE
  15.     C:\foo\> .New-InternalSwitch.ps1
  16.     VERBOSE: New-InternalSwitch will create a new virtual network.
  17.     Name      SwitchType NetAdapterInterfaceDescription
  18.     ----      ---------- ------------------------------
  19.     Internal  Internal
  20. #>
  21. # Import Hyper-V Module
  22. Import-Module Hyper-V
  23. Try {New-VMSwitch -Name Internal -SwitchType Internal -ComputerName LocalHost -Verbose}
  24. Catch { "Failed to create switch"; $error[0] }
  25. # End New-InternalSwitch.ps1

Saturday, 9 January 2010

Get-VMMemory

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays the virtual Memory assigned to Hyper-V 
  4.     VMs on a given host. 
  5. .DESCRIPTION 
  6.     This script uses The Hyper-V module from Codeplex to first 
  7.     get all the VMs on a given server, then display the memory  
  8.     allocated to each VM. 
  9. .NOTES 
  10.     File Name  : get-VMMemory.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13.                  and HyperV module from Codeplex 
  14.                  http://pshyperv.codeplex.com 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18. .EXAMPLE 
  19.     PSH [C:\Foo]: c:\foo\get-VMMemory.ps1 Foo21 
  20.     On Server Foo21 there are 2 VMs as follows: 
  21.     Virtual Machine                       Memory 
  22.     SQL-2008-R2-CTP                          768 
  23.     Server-2008-R2                           768 
  24. .EXAMPLE 
  25.     PSH [C:\Foo]: "Server2" | c:\foo\get-VMMemory.ps1 Foo21 
  26.     On Server Server2 there are 3 VMs as follows: 
  27.     Virtual Machine                       Memory 
  28.     Server-2008-R2-1                         768 
  29.     Server-2008-R2-2                         768 
  30.     Server-2008-R2-3                         768 
  31. #> 
  32.  
  33. # Parameter is the machine to look at 
  34. param
  35. [Parameter(Position=0, Mandatory=$false,ValueFromPipeLine=$true)]  
  36. [string] $Computer = "MyServer" 
  37. ## 
  38. # Start of script 
  39. ## 
  40.  
  41. # Import the module 
  42. Import-Module HyperV 
  43.  
  44. # Get all the VMs on the target system 
  45. $Vms = Get-Vm -Server $Computer 
  46.  
  47. # Now loop through the VMs and display memory allocated 
  48. "On Server {0} there are {1} VMs as follows:" -f $Computer,$Vms.count 
  49. "{0,-30}    {1,10}" -f "Virtual Machine", "Memory" 
  50. Foreach ($Vm in $Vms) { 
  51. $Mem = Get-Vmmemory $Vm
  52. "{0,-30}    {1,10}" -f $Vm.Elementname,$Mem.Virtualquantity 
  53. }  
  54. # End of script