Skip to content

Instantly share code, notes, and snippets.

@iainbrighton
iainbrighton / GetDscResource.ps1
Created November 21, 2015 23:42
Enumerate local DSC Resources
function TestDscResourceModule {
<#
.SYNOPSIS
Tests whether the specified PowerShell module directory is a DSC resource.
#>
[CmdletBinding()]
[OutputType([System.Boolean])]
param (
[Parameter(Mandatory, ValueFromPipeline)] [System.String] $Path
Measure-Command {
$SAMLogArrayList = New-Object -TypeName System.Collections.ArrayList -ArgumentList @()
$NumOfFiles = (Get-ChildItem -file $directory).count
$counter = 1
Foreach($file in (Get-ChildItem -file $directory).FullName){
$PercentComplete = (($counter / $NumOfFiles) * 100)
$PercentComplete = [math]::Round($PercentComplete, 2)
Write-Progress -id 1 -Activity "Reading Files." -PercentComplete $PercentComplete -CurrentOperation "$($PercentComplete)% complete" -Status "Please wait"
$LinesInFile = (Get-Content $file).count
$x = 1
Measure-Command {
$SAMLogArrayList = New-Object -TypeName System.Collections.ArrayList -ArgumentList @()
$NumOfFiles = (Get-ChildItem -file $directory).count
$counter = 1
Foreach($file in (Get-ChildItem -file $directory).FullName) {
$PercentComplete = (($counter / $NumOfFiles) * 100)
$PercentComplete = [math]::Round($PercentComplete, 2)
Write-Progress -id 1 -Activity "Reading Files." -PercentComplete $PercentComplete -CurrentOperation "$($PercentComplete)% complete" -Status "Please wait"
$fileContent = Get-Content $file
for ($i = 0; $i -lt $fileContent.Count; $i++)
@iainbrighton
iainbrighton / Bootstrap.ps1
Last active May 10, 2016 14:22
Lability Bootstrap
#requires -RunAsAdministrator
#requires -Version 4.0
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
param (
## Name of the node in the PowerShell DSC configuration document (.psd1) to apply
[Parameter()] [ValidateNotNullOrEmpty()]
[System.String] $NodeName,
## Override the root path, i.e. when not running from an .Iso image
function Convert-HashToString {
[CmdletBinding()]
[OutputType([System.String])]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[System.Collections.Hashtable] $Hashtable,
[Parameter(ValueFromPipelineByPropertyName)]
[System.Int32] $Indentation,
@iainbrighton
iainbrighton / Lability_Gen1_Media.ps1
Created August 4, 2016 07:54
Register Lability Gen1 media
## Register existing Windows 7 x64 Enterprise Evaluation VHD(X) media
$WIN7_x64_Enterprise_EN_Eval = @{
Id = 'WIN7_x64_Enterprise_EN_Eval';
Filename = 'WIN7_x64_Enterprise_EN_Eval_022016.vhdx';
Description = 'Windows 7 Enterprise 64bit English Evaluation Patched 02/16';
Architecture = 'x64';
MediaType = 'VHD';
Uri = '\\10.100.50.1\Public\ParentDisks\Win7_x64_Enterprise_EN_Eval_022016.vhdx';
CustomData = @{
PartitionStyle = 'MBR'; ## This creates a Gen1 VM
@iainbrighton
iainbrighton / Microsoft.PowerShell_profile.ps1
Created November 10, 2016 21:51
PowerShell Console Profile
## Set the default console colours
$Host.PrivateData.ErrorBackgroundColor = 'DarkMagenta';
$Host.PrivateData.WarningBackgroundColor = 'DarkMagenta';
$Host.PrivateData.VerboseForegroundColor = 'Cyan';
$Host.PrivateData.VerboseBackgroundColor = 'DarkMagenta';
@iainbrighton
iainbrighton / Profile.ps1
Last active January 7, 2018 00:23
Default PowerShell Profile
if (Test-Path -Path "$env:USERPROFILE\Dropbox\PowerShell" -PathType Container) {
if ($Host.Name -ne 'Visual Studio Code Host') {
## Always default to repository root when loading in VSCode
Set-Location -Path "$env:USERPROFILE\Dropbox\PowerShell";
}
if (Test-Path -Path "$env:USERPROFILE\Dropbox\PowerShell\Modules" -PathType Container) {
if ($env:PSModulePath -notmatch "$(($env:USERPROFILE).Replace('\','\\'))\\Dropbox\\PowerShell\\Modules") {
$env:PSModulePath += ";$env:USERPROFILE\Dropbox\PowerShell\Modules";
@iainbrighton
iainbrighton / Get-MofModule.ps1
Created February 4, 2017 16:06
Scans a Desired State Configuration .mof file and returns the declared/required modules.
function Get-MofModule {
<#
.SYNOPSIS
Scans a Desired State Configuration .mof file and returns the declared/
required modules.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[System.String] $Path
@iainbrighton
iainbrighton / Get-MofModule.ps1
Created February 4, 2017 16:06
Scans a Desired State Configuration .mof file and returns the declared/required modules.
function Get-MofModule {
<#
.SYNOPSIS
Scans a Desired State Configuration .mof file and returns the declared/
required modules.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[System.String] $Path