Skip to content

Instantly share code, notes, and snippets.

View gaelcolas's full-sized avatar
🏠
Working from home

Gael gaelcolas

🏠
Working from home
View GitHub Profile
@gaelcolas
gaelcolas / DynamicParam.draft.ps1
Last active August 1, 2019 16:30
PowerShell Generating dynamic parameters and parameter sets to wrap around a Class for easy instantiation such as new-Type -ctorArg1 $val -property $val2
#region Get-TypeDynamicParam
function Get-DynamicParamFromTypeName {
Param(
[string]
$TypeName
)
function New-ParamAttribute {
Param(
[Parameter(Mandatory=$true,ValueFromPipeLine=$false,ValueFromPipelineByPropertyName=$true, position=0)]
[string]
. .\lib.common\MethodHelpers.ps1
. .\lib.common\PowerObject.ps1
function Resolve-DNSHost {
[cmdletBinding()]
Param ()
DynamicParam {
Get-DynamicParamForMethod -method ([System.Net.Dns]::Resolve)
}
process {
try
. .\lib.common\MethodHelpers.ps1
. .\lib.common\PowerObject.ps1
function Get-Color{
[cmdletBinding()]
Param ()
DynamicParam {
[System.Drawing.Color]::FromName,[System.Drawing.Color]::FromKnownColor | Get-DynamicParamForMethod
}
process {
@gaelcolas
gaelcolas / runKilaSuitWMF5Install.ps1
Created July 9, 2016 21:18
Running Ryan Rates install WMF5 from github
Invoke-Expression (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/kilasuit/PoshFunctions/Dev/Scripts/Install-WMF5.ps1’)
@gaelcolas
gaelcolas / NewVMwithDiffDisk.ps1
Created July 9, 2016 21:28
Create VM with differencing disks
New-VHD -Differencing -ParentPath .\BaseWMF5.vhd -Path .\BaseWMF5_diff.vhd
New-VM -Name TestBase -BootDevice IDE -VHDPath .\BaseWMF5_diff.vhd -SwitchName inet -Path .\hyperv\
Start-VM TestBase
@gaelcolas
gaelcolas / InstallPester.ps1
Created July 9, 2016 21:32
Install Pester with WMF5 and PackageManagement module
Install-PackageProvider -Name nuGet -Force -ForceBootstrap
Import-PackageProvider -Name nuGet -Force -ForceBootstrap
#Restart your PowerShell console / ISE.
Find-package Pester | install-package
@gaelcolas
gaelcolas / TestImageHasWMF5.ps1
Created July 9, 2016 21:34
Testing WMF5 is installed with Pester test
Describe 'Testing Image' {
It 'Should have WMF5' {
$PSVersionTable.PSVersion.Major -ge 5 | should be $true
}
}
@gaelcolas
gaelcolas / new_unattend_iso.ps1
Created July 9, 2016 21:45
create ISO with my Unattend.xml file
. '.\TestKitchen\script\IsoFile.ps1'
#create ISO with my Unattend.xml file
New-IsoFile -Source .\TestKitchen\Unattend.xml -Path .\TestKitchen\Unattendxml.iso -Force -Title MyISO
@gaelcolas
gaelcolas / NewVMwDiffDiskAndIsoAttached.ps1
Created July 9, 2016 21:47
Create VM on Diff disk and attach unattendxml iso before starting
New-VHD -Differencing -ParentPath .\BaseWMF5.vhd -Path .\BaseWMF5_diff.vhd
New-VM -Name TestBase -BootDevice IDE -VHDPath .\BaseWMF5_diff.vhd -SwitchName inet -Path .\hyperv\
set-VMDvdDrive -VMName TestBase -Path .\Unattendxml.iso
Start-VM TestBase
@gaelcolas
gaelcolas / PatchWindowsImageDISMCmdlet.ps1
Created July 9, 2016 21:54
Patch and modify a Windows VHD Image with DISM Commandlets
Mount-WindowsImage -ImagePath .\baseNoWMF5.vhd -Path ./VHD -Index 1
Add-WindowsPackage -PackagePath .\Win8.1AndW2K12R2-KB3134758-x64.msu -Path .\VHD
Use-WindowsUnattend -UnattendPath C:\src\winopsconf\TestKitchen\Unattend.xml -Path .\VHD
Dismount-WindowsImage -Path .\VHD -Save