Skip to content

Instantly share code, notes, and snippets.

View SteveL-MSFT's full-sized avatar

Steve Lee SteveL-MSFT

View GitHub Profile
@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 / 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
[DscResource()]
class FileContentResource {
[DscProperty(Key)]
[string] $filePath
[DscProperty(Mandatory)]
[string] $content
[FileContentResource] Get()
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
@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(
[Parameter(ValueFromPipeline)]
[string]$json,
[Parameter(Mandatory,Position=0)]
[string]$find
)
$obj = ConvertFrom-Json -InputObject $json -Depth 100
param(
[Parameter(ValueFromPipeline)]
[string]$json
)
$obj = ConvertFrom-Json -InputObject $json -Depth 100 -AsHashtable
$location = "/"
function Test-Location ($path) {
param(
[Parameter(ValueFromPipeline=$true)]
[ValueType]
$profileEvent
)
begin {
$profileEvents = [System.Collections.Generic.List[object]]::new()
}
hello world
]633;Completions?
]