Skip to content

Instantly share code, notes, and snippets.

View mgreenegit's full-sized avatar

Michael Greene mgreenegit

  • Microsoft
View GitHub Profile
@mgreenegit
mgreenegit / pocARGCompleter.ps1
Created September 23, 2022 16:15
POC ARG Completer
function smartComplete {
param ( $commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters )
$possibleValues = [array](Search-AzGraph -Query "resourcecontainers | where ['type'] == 'microsoft.resources/subscriptions' | project name").name
if ($fakeBoundParameters) {
@mgreenegit
mgreenegit / show.ps1
Created September 15, 2022 15:18
PS slideShow
function wait { $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') }
function line { write-host '' }
function getslides {param([string]$path) Get-Childitem -Path $path -Filter slide*.md}
function slide {
param(
[string]$path
)
$slides = getslides $path
foreach ($i in 0..$slides.count) {
$slide = Join-Path $path slide$i.md
@mgreenegit
mgreenegit / NetFirewallDsc Example
Last active August 5, 2022 13:48
TODO: add enum for gposetting type, try splitting details into a reasons array
function Get-Resource {
param(
[DscProperties]$DscProperties
)
$psPath = Join-Path ([System.Environment]::SystemDirectory) 'WindowsPowerShell\v1.0\powershell.exe'
& $psPath -noProfile -command {
param(
$Name
)
$Env:PSModulePath += ";$PSHOME\Modules\NetSecurity"
@mgreenegit
mgreenegit / ResourceSample2.psm1
Created May 3, 2022 16:31
Simple example of class resource for Windows service
# This is the Get function
function Get-Resource {
param(
[string]$status,
[string]$starttype
)
$service = Get-Service winmgmt
# Information returned by Get will be available in Azure via API
return @{
@mgreenegit
mgreenegit / ResourceSample.psm1
Created April 30, 2022 19:48
An example DSC resource where only the functions need to be edited
# This is the Get function
function Get-Resource {
param(
[Parameter(Mandatory = $true)]
[String]
$Ensure,
[Parameter(Mandatory = $true)]
[string]
$PropertyA,
[Parameter(Mandatory = $true)]
@mgreenegit
mgreenegit / get-poldef.ps1
Created July 23, 2021 13:50
Search for built-in policy definitions
get-azpolicydefinition |
? {$_.Properties.PolicyType -eq "BuiltIn" -AND $_.Properties.DisplayName -like "*baseline*"} |
select policyDefinitionId -ExpandProperty Properties |
select policyDefinitionId, DisplayName |
fl
function Get-AvailableMemory {
$Mem = '' | Select AvailableMemory
$Mem.AvailableMemory = Get-Counter '\Memory\Available MBytes' | % CounterSamples | % CookedValue
return $Mem
}
New-Alias Mem Get-AvailableMemory -Scope Global
@mgreenegit
mgreenegit / PoshMon.psm1
Created September 18, 2015 16:12
Simple function to render results of a command in real time (or near real time)
function PoshMon {
param (
[Parameter(Mandatory=$True,ValueFromPipelineByPropertyName=$True)]
[string]$command,
[Int32]$seconds = 300
)
Begin {
[System.Console]::Clear()
[console]::CursorSize = 1
$now = Get-Date
@mgreenegit
mgreenegit / foldertovirtualmachine.psm1
Last active June 2, 2023 15:10
Copy the contents of a folder in to a virtual machine
function copy-foldertovirtualmachine {
param(
[parameter (mandatory = $true, valuefrompipeline = $true)]
[string]$VMName,
[string]$Folder = '.\'
)
foreach ($File in (Get-ChildItem $Folder -recurse | ? Mode -ne 'd-----')){
Copy-VMFile -VM (Get-VM $VMName) -SourcePath $file.fullname -DestinationPath $file.fullname -FileSource Host -CreateFullPath -Force}
}
@mgreenegit
mgreenegit / WSManTrust.psm1
Last active December 3, 2020 22:55
Simple set of commands to maintain the WSMan trusted hosts list
function Get-WSManTrust {
(Get-Item -Path WSMan:\localhost\Client\TrustedHosts | % Value).split(',')
}
function New-WSManTrust {
param(
[string]$hostname
)
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value $hostname -Concatenate -Force
}