Skip to content

Instantly share code, notes, and snippets.

@pkothree
pkothree / GetSearchResult.ps1
Last active July 19, 2019 14:13
Get a Search Result from SharePoint Search
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"
@pkothree
pkothree / InstallHyperV.ps1
Created July 12, 2019 21:21
Automatically deploy Hyper-V machines with PowerShell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell
@pkothree
pkothree / CreateVM.ps1
Created July 12, 2019 21:17
Automatically deploy Hyper-V machines with PowerShell
###
# 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)
@pkothree
pkothree / SetIPAndRestart.ps1
Created July 12, 2019 21:16
Automatically deploy Hyper-V machines with PowerShell
# 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*
@pkothree
pkothree / StartVM.ps1
Created July 12, 2019 21:13
Automatically deploy Hyper-V machines with PowerShell
# Start Hyper-V VM
Start-VM –ComputerName $VMHost –Name $VMName
@pkothree
pkothree / AddSecondHDD.ps1
Created July 12, 2019 21:12
Automatically deploy Hyper-V machines with PowerShell
# 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
@pkothree
pkothree / CreateUpdateVM.ps1
Created July 12, 2019 21:11
Automatically deploy Hyper-V machines with PowerShell
# 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
{
@pkothree
pkothree / VMSizes.ps1
Created July 12, 2019 21:07
Automatically deploy Hyper-V machines with PowerShell
switch($VMSize)
{
"S1"
{
$MemoryStartupBytes = 1GB
$VHDSize = 10GB
$ProcCount = 1
$MemoryMinimumBytes = 512MB
$MemoryMaximumBytes = 1GB
$Generation = "2"
@pkothree
pkothree / BuildCredentials.ps1
Created July 12, 2019 21:06
Automatically deploy Hyper-V machines with PowerShell
# Build VM Credentials
$username = ""
$pw = ""
$secpassword = ConvertTo-SecureString $pw -AsPlainText -Force
$VMCredentials= New-Object System.Management.Automation.PSCredential ($username, $secpassword)
@pkothree
pkothree / generalize.ps1
Created July 12, 2019 21:01
Start-Process -FilePath C:\Windows\System32\Sysprep\Sysprep.exe -ArgumentList '/generalize /oobe /shutdown /quiet'
Start-Process -FilePath C:\Windows\System32\Sysprep\Sysprep.exe -ArgumentList '/generalize /oobe /shutdown /quiet'