Skip to content

Instantly share code, notes, and snippets.

View SteveL-MSFT's full-sized avatar

Steve Lee SteveL-MSFT

View GitHub Profile
param(
[Parameter(ValueFromPipeline)]
[string]$json
)
$obj = ConvertFrom-Json -InputObject $json -Depth 100 -AsHashtable
$location = "/"
function Test-Location ($path) {
param(
[Parameter(ValueFromPipeline)]
[string]$json,
[Parameter(Mandatory,Position=0)]
[string]$find
)
$obj = ConvertFrom-Json -InputObject $json -Depth 100
@SteveL-MSFT
SteveL-MSFT / get-winrtversion.ps1
Created August 27, 2021 03:07
Example calling WnRT API from PS7 to get Windows version information
# adapted from https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/identifying-windows-version-part-2
# download and unzip latest https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref and get these dlls from the 'lib' folder
Add-Type -AssemblyName ./winrt.runtime.dll
Add-Type -AssemblyName .\Microsoft.Windows.SDK.NET.dll
# define call and information to query
[Collections.Generic.List[System.String]]$names = 'DeviceFamily',
'OSVersionFull',
'FlightRing',
param($address)
$parcelUrl = 'https://gismaps.kingcounty.gov/parcelviewer2/addSearchHandler.ashx?add='
$parcel = Invoke-RestMethod ($parcelUrl + [uri]::EscapeUriString($address))
$id = $parcel.items.pin
$propertyUrl = 'https://gismaps.kingcounty.gov/parcelviewer2/pvinfoquery.ashx?pin='
$property = Invoke-RestMethod ($propertyUrl + $id)
$property.items
[DscResource()]
class FileContentResource {
[DscProperty(Key)]
[string] $filePath
[DscProperty(Mandatory)]
[string] $content
[FileContentResource] Get()
@SteveL-MSFT
SteveL-MSFT / AutoCorrect.ps1
Last active March 27, 2021 01:09
Example script showing auto-correction with DSC and PS7
Start-Job {
# path would need to be updated to where you have the FileContentResource.psm1 example saved
if ($env:PSModulePath -notlike "*demo*") {
$env:PSModulePath += [System.IO.Path]::PathSeparator + '/Users/steve/test/demo'
}
# temporarily ensure latest version required for this demo is loaded
Import-Module /Users/steve/test/demo/PSDesiredStateConfiguration -Force
@SteveL-MSFT
SteveL-MSFT / FileContentResource.psm1
Last active September 2, 2021 01:29
Example DSC class-based resource for file content
# this is an example of what a converted script resource would look like as a class keeping
# the private functions
[DscResource()]
class FileContentResource {
[DscProperty(Key)]
[string] $filePath
[DscProperty(Mandatory)]
@SteveL-MSFT
SteveL-MSFT / Get-Commands.ps1
Created March 16, 2021 15:06
Find modules/commands used by script
param($file)
$tokens = $null
$err = $null
$file = Resolve-Path $file
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$tokens, [ref]$err)
$commands = $ast.FindAll({$true},$true) | ? { $_ -is [System.Management.Automation.Language.CommandAst] } | % { $_.CommandElements[0].Value } | Sort-Object -Unique
$sources = [System.Collections.Generic.List[string]]::new()
$commands | % {
$parameters = @{
Key = 'F7'
BriefDescription = 'ShowMatchingHistoryOcgv'
LongDescription = 'Show Matching History using Out-ConsoleGridView'
ScriptBlock = {
param($key, $arg) # The arguments are ignored in this example
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
$history = [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems().CommandLine | Select-Object -Unique
1..100|%{$_%15?$_%3?$_%5?$_ :'Buzz':'Fizz':'FizzBuzz'|Write-Host}