Skip to content

Instantly share code, notes, and snippets.

View brianbunke's full-sized avatar

Brian Bunke brianbunke

View GitHub Profile
@brianbunke
brianbunke / NewSplit.ps1
Last active November 12, 2015 00:28
2015-11 PowerShell.org Scripting Games Puzzle
# Ideally this is [string[]]
param([string]$VMNameStr)
# Copying from old: Split up names by commas, trim the ends, output to screen
$VMNameStr -split "," | %{$_.trim()}
@brianbunke
brianbunke / PSGames-Dec2015.ps1
Last active December 8, 2015 01:53
2015-12 PowerShell Scripting Games Puzzle
$List = @'
1 Partridge in a pear tree
2 Turtle Doves
3 French Hens
4 Calling Birds
5 Golden Rings
6 Geese a laying
7 Swans a swimming
8 Maids a milking
9 Ladies dancing
function Invoke-PowerCSV {
[CmdletBinding()]
param (
# Position 1 is implied here, and doesn't need to be specified
[Parameter(Mandatory = $true)]
[string[]]$ComputerName,
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
$InputFile,
@brianbunke
brianbunke / PSGames-201601.ps1
Last active January 4, 2016 06:45
PSGames-201601
function Get-Uptime {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[string[]]$ComputerName = $env:COMPUTERNAME
)
BEGIN {
# Define $Results array to append each computer into; get the current date once
@brianbunke
brianbunke / Get-Diacritic.ps1
Created March 7, 2016 02:43
PSGames-201603-Advanced
function Get-Diacritic {
<#
.SYNOPSIS
Find filenames with diacritic marks, export the list to CSV, and email the list to your boss.
.LINK
http://powershell.org/wp/2016/03/05/2016-march-scripting-games-puzzle/
#>
[CmdletBinding()]
param (
@brianbunke
brianbunke / Draft1-Measure-LastCommand.ps1
Created January 7, 2017 07:28
Illustrating the initial effects of "Update-ScriptFileInfo -Force"
<#PSScriptInfo
.VERSION 1.0
.GUID a9323abc-0567-4c4f-ad8e-cdd4cb236e3a
.AUTHOR Brian
.COMPANYNAME
@brianbunke
brianbunke / Update-ScriptFileInfo-2017Jan.ps1
Last active March 19, 2021 00:58
Using "Update-ScriptFileInfo" properly in January 2017
$Splatting = @{
Path = "$env:USERPROFILE\Desktop\Your-Script.ps1"
Version = '1.0.0' # http://semver.org ;)
# GUID will randomly auto-generate for new scripts
# Only specify GUID if you're going to overwrite existing properties on an updated script version
Author = 'YourPSGalleryUsername'
Description = 'Explain your script to prospective users, preferably in one sentence.'
# CompanyName
# Copyright
Tags = @('super','awesome','radical')
@brianbunke
brianbunke / Mock-VM-Attempt1.ps1
Last active January 13, 2017 23:48
Trying to figure out how to mock a PowerCLI VM object
# This code doesn't work. :) Soliciting feedback
# Just started duplicating info from here:
# (Get-VM 'ExampleVM') | gm | Where MemberType -eq 'Property' | Select Name,Definition
$r = "c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk\VMware.VimAutomation.Sdk.Types.dll",
"c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core\VMware.VimAutomation.ViCore.Types.dll"
Add-Type -ReferencedAssemblies $r -TypeDefinition "
using VMware.VimAutomation.ViCore.Types.V1;
@brianbunke
brianbunke / Mock-VM-Attempt2.ps1
Created January 15, 2017 18:41
Mock a PowerCLI VM object
# Barely working :D
# Follows my previous Gist, https://gist.github.com/brianbunke/13e32ae67a9232d2224601e937eebba7
# http://theshellnut.com/exploring-powercli-types/
# http://stackoverflow.com/questions/14141043/resolving-an-ambiguous-reference
ipmo VMware.VimAutomation.Core
$r = "c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Sdk\VMware.VimAutomation.Sdk.Types.dll",
"c:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules\VMware.VimAutomation.Core\VMware.VimAutomation.ViCore.Types.dll",
#Requires -Version 3
Import-Module VMware.VimAutomation.Core
Connect-VIServer XXXXX
$Report = New-Object 'System.Collections.Generic.List[PSCustomObject]'
$VM = Get-VM
$VM | ForEach-Object {
$Obj = [PSCustomObject][ordered]@{
VMName = $_.Name