Skip to content

Instantly share code, notes, and snippets.

@JamesDawson
JamesDawson / setup-pyenv-poetry-windows.ps1
Last active November 14, 2024 15:38
Setup python, pyenv-win and poetry on Windows
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string] $PythonVersion
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
Set-StrictMode -Version Latest
@JamesDawson
JamesDawson / multiple-azurecli-security-contexts-demo.ps1
Last active May 15, 2020 12:00
Using multiple azure-cli security contexts (PowerShell demo)
$ErrorActionPreference = 'Stop'
# setup temporary profile path for the alternative user
$altIdProfilePath = Join-Path ([io.path]::GetTempPath()) '.azure-altId'
try {
# check whether already logged-in
$currentToken = $(az account get-access-token) | ConvertFrom-Json
if ([datetime]$currentToken.expiresOn -le [datetime]::Now) {
throw
}
@JamesDawson
JamesDawson / New-MockVariableSet.ps1
Created October 7, 2017 20:57
Creating an (incomplete) OctoPosh variableset object
function New-MockVariableSet([hashtable]$props)
{
$varset = new-object 'OctoPosh.Model.OutputOctopusVariableSet'
$varset.ID = $props.Id
$varset.LibraryVariableSetName = $props.Name
$varset.Variables = new-object 'System.Collections.Generic.List[OctoPosh.Model.FriendlyVariable]'
$varset.Resource = new-object 'Octopus.Client.Model.VariableSetResource'
$varset.Resource.Id = $props.Id
foreach ($v in $props.Variables)
gci *.mof | % { gc -raw $_ | % { $patched = $_ -replace "\[version" ,"[ClassVersion"; $patched = $patched -replace "MSFT_BaseResourceConfiguration" ,"OMI_BaseResource" }; sc $_ $patched }
param
(
[Parameter(Mandatory) ]
[String[]] $ComputerName,
[ValidateRange( 1,3 )]
[uint32] $flag = 1
)
Invoke-CimMethod -ComputerName $ComputerName -Namespace root/microsoft/windows/desiredstateconfiguration `
param
(
[Parameter(Mandatory) ]
[String[]] $ComputerName,
[ValidateRange( 1,3 )]
[uint32] $flag = 3
)
Invoke-CimMethod -ComputerName $ComputerName -Namespace root/microsoft/windows/desiredstateconfiguration `
param
(
$resources = @(),
$pullServerRoot = "C:\ProgramData\PSDSCPullServer"
)
function New-Hash
{
param
(
Configuration SetPullMode
{
Node Server01
{
# Set the DSC engine (LCM) to Pull mode
LocalConfigurationManager
{
ConfigurationID = "e528dee8-6f0b-4885-98a1-1ee4d8e86d82"
ConfigurationMode = "ApplyOnly"
RefreshMode = "Pull"
Configuration SetPullMode
{
Node Server01
{
# Set the DSC engine (LCM) to Pull mode
DesiredStateConfigurationSettings LCM
{
ConfigurationID = "e528dee8-6f0b-4885-98a1-1ee4d8e86d82"
ConfigurationMode = "Pull"
DownloadManagerName = "WebDownloadManager"
Configuration PullDemo
{
Node Server01
{
Computer RenameServer01
{
Name = "NewHostName"
}
}
}