This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | |
| { | |
| Add-PSSnapin Microsoft.SharePoint.PowerShell | |
| } | |
| [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Search.Administration.SearchObjectLevel") | |
| [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search.Administration.CrawlLog") | |
| # text that we are looking for | |
| $matchText = "SharePoint" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### | |
| # Danny Davis | |
| # Create VM in Hyper-V | |
| # Created: 04/23/19 | |
| # Modified: 06/12/19 | |
| ### | |
| $environmentName = "Example" # CustomerName | |
| $type = "S" # Client (C) or Server (S) | |
| $OS = "16" # Windows Server 16 (16), Win Server 19 (19), Win10 (10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Waits till VM is running | |
| do{ | |
| $RunningVM = Get-VM -ComputerName $VMHost -Name $VMName | |
| $state = $RunningVM.State | |
| }while($state -ne "Running") | |
| # Break to get OS Version to ensure that Windows is up | |
| do{ | |
| try{ | |
| Get-WMIObject -Class Win32_OperatingSystem -ComputerName $VMName -Credential $VMCredentials | Select-Object *Version -ExpandProperty Version* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Start Hyper-V VM | |
| Start-VM –ComputerName $VMHost –Name $VMName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add second VHD | |
| try | |
| { | |
| New-VHD -Path $VHDPath -SizeBytes $VHDSize | |
| } | |
| catch{ "An error occured during the creation of the second VHD in Path "+$VHDPath} | |
| try | |
| { | |
| Add-VMHardDiskDrive -VMName $VMName -ControllerType SCSI -Path $VHDPath |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create new VM and basic VHD | |
| try | |
| { | |
| # "Copy" HDD of the Parent OS | |
| New-VHD -Path $VHDPathOS -ParentPath $ParentVHDOS #-Differencing | |
| } | |
| catch{ "An error occured during the creation of of VHD OS in Path "+$VHDPathOS } | |
| try | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| switch($VMSize) | |
| { | |
| "S1" | |
| { | |
| $MemoryStartupBytes = 1GB | |
| $VHDSize = 10GB | |
| $ProcCount = 1 | |
| $MemoryMinimumBytes = 512MB | |
| $MemoryMaximumBytes = 1GB | |
| $Generation = "2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Build VM Credentials | |
| $username = "" | |
| $pw = "" | |
| $secpassword = ConvertTo-SecureString $pw -AsPlainText -Force | |
| $VMCredentials= New-Object System.Management.Automation.PSCredential ($username, $secpassword) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Start-Process -FilePath C:\Windows\System32\Sysprep\Sysprep.exe -ArgumentList '/generalize /oobe /shutdown /quiet' |