Skip to content

Instantly share code, notes, and snippets.

View mgreenegit's full-sized avatar

Michael Greene mgreenegit

  • Microsoft
View GitHub Profile
@mgreenegit
mgreenegit / FixCursor.psm1
Created April 10, 2015 12:53
If the cursor is not visible in the PowerShell console, this will correct it
function fixcursor
{
[console]::CursorSize = 25
}
@mgreenegit
mgreenegit / TestDSCPullServer.ps1
Created April 17, 2015 15:58
Validate DSC Pull Server Functionality
# This function is meant to simplify a check against a DSC Pull Server. If you do not use the default service URL, you will need to adjust accordingly.
function Verify-DSCPullServer ($fqdn) {
([xml](invoke-webrequest "https://$($fqdn):8080/psdscpullserver.svc" | % Content)).service.workspace.collection.href
}
Verify-DSCPullServer 'INSERT SERVER FQDN'
@mgreenegit
mgreenegit / CWI_Fix.ps1
Created May 11, 2015 13:42
Fix: Convert-WindowsImage run on Windows 10
# https://gallery.technet.microsoft.com/scriptcenter/Convert-WindowsImageps1-0fe23a8f
# Update line 3044
# In version 6.3, the evaluator was comparing strings to integers.
# Replacing this line will use version objects to check the version of Windows and integers for the build number.
$isWin8 = (((new-object Version $os.Version) -ge (new-object Version 6.2)) -and ([uint32]$os.BuildNumber -ge $lowestSupportedBuild))
@mgreenegit
mgreenegit / dscticker.ps1
Created July 7, 2015 13:27
Stashing a quick prototype of a counter to display when DSC will next evaluate a node. PDT has a much better timer output.
$LastStatus = (Get-DscConfigurationStatus).StartDate
$Frequency = (Get-DscLocalConfigurationManager).ConfigurationModeFrequencyMins
while ( (Get-Date) -lt ($LastStatus.AddMinutes($Frequency)) )
{
Write-Host ((Get-Date) - ($LastStatus.AddMinutes($Frequency)))
}
@mgreenegit
mgreenegit / hvcfg.ps1
Last active August 29, 2015 14:27
Hyper-V Configuration
# This script is intended to configure Hyper-V on a Windows 10 machine where virtual disks are already present.
Configuration testbox
{
Import-DscResource -module xHyper-V, xDismFeature
Node localhost
{
xDismFeature HyperV
{
Ensure = 'Present'
@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
}
@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 / 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
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 / 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