PowerShell DSC – LocalConfigurationManager cycle behaviour

LCM will start the 15 minute cycle based on: • A new metaconfig is applied using Set-DscLocalConfigurationManager • A machine restart • For any condition where the timer process experiences a crash, that will be detected within 30 seconds and the cycle will be restarted The start time is absolute. This means if an operation begins at T0…

2

Azure – PowerShell setting Blob Tiers

function Set-AgedBlobsToTier  { PARAM ( [Parameter(Mandatory = $true)] [int] $AgeInDays, [Parameter(Mandatory = $true)] [Microsoft.WindowsAzure.Storage.Blob.Standardblobtier] $StorageTier, [Parameter(Mandatory = $true)] [string]$ResourceGroupName, [Parameter(Mandatory = $true)] [string]$StorageAccountName )    $StorageAccountName = $StorageAccountName.ToLower()      if  (Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -EA SilentlyContinue)  { $StorageAccountKeys    = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName $StorageAccountKey     = $StorageAccountKeys[0].Value $StorageAccountContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey…

1

PowerShell – reinstall Windows 10 Store app

#Reinstall-StoreApp.ps1 #Requires -RunAsAdministrator $Store=Get-Appxpackage -Allusers | Where-Object {$_.PackageFullName -match ‘WindowsStore’} | Sort-Object -Property Version -Descending | Select-Object -First 1 $PackageName=$Store.PackageFullName $StoreManifest = “C:\Program Files\WindowsApps\$PackageName\AppxManifest.xml” if (Test-Path -Path $StoreManifest) { Add-AppxPackage -register $StoreManifest -DisableDevelopmentMode }

0

PowerShell Azure – Get-AzureExtensionHighestVersion

function Get-AzureExtensionHighestVersion {    [CmdletBinding()]    PARAM ([string]$extension, [string] $location=’AustraliaEast’)     $sortProps = @{Expression = “PublisherName”; Descending = $True}, @{Expression = “Type”; Descending = $True},@{Expression = “Version”; Descending = $True}    $Results= Get-AzureRmVmImagePublisher -Location $location |      Get-AzureRmVMExtensionImageType |       Get-AzureRmVMExtensionImage |        Where-Object {$_.Type -LIKE “*$extension*”}   #replace version…

0

PowerShell – DSC Linux MOFs and logs

working with DSC on Linux, there are a few things to know that don’t seem to be documented anywhere obvious.  OMI stuff  lives in /opt/omi/lib /opt/omi/bin  For troubleshooting you look at the logs which are here: cat /var/opt/omi/log/omiserver.log         #the OMI CIM server cat /var/opt/omi/log/dsc.log               #the LCM and DSC logging. Start your…

0

PowerShell Azure – Invoke-AzureRmVMRunCommand

Invoke-AzureRmVMRunCommand has a parameter -CommandId which the single example shows as -CommandId ‘RunPowerShellScript’ -ScriptPath ‘sample.ps1’ but the question that raises is – what other values can I give? A colleague showed me how to get the list of various CommandId values: Get-AzureRmVMRunCommandDocument -Location AustraliaEast EnableRemotePS – Configure the machine to enable remote PowerShell. (Windows) Ipconfig – List…

2

PowerShell – SharpCompress and untar

#needed to untar a tar.gz file and found the SharpCompress package, which will do it all! #region InstallPackage SharpCompress if  (-NOT (Get-Package -Name ‘SharpCompress’ -ErrorAction SilentlyContinue)) { #need to install it if (Find-Package -Name ‘SharpCompress’ -ErrorAction SilentlyContinue) { Find-Package -Name SharpCompress  | Install-Package -Verbose } else { if (-NOT (Get-PackageSource -Name ‘nuGet.org v2’ -ErrorAction SilentlyContinue))…

0

PowerShell – Get-Credential and certificates

Matthew Bongiovi  had a discussion on Get-Credential and how it works. So useful, that I thought I’d cut/paste it here so that you and I can refer to it in future! See below:   The Get-Credential cmdlet generates the prompt using the CredUIPromptForCredentials function. The documentation for that function says: “In the case of credentials…

0

PowerShell Azure – find a sku offer publisher

# who is the publisher for FreeBSD? What offer? What sku? # Find-AzureSKU bsd function Find-AzureSKU  {   Param ([parameter(Mandatory=$true,HelpMessage=’Enter a partial string of the  product’)]   [String] $sku,   [String] $location=’australiaeast’  )   $publishers = Get-AzureRmVMImagePublisher -location $location   foreach ($publisher in $publishers) {      $offers=Get-AzureRmVMImageOffer -location $location `        …

0

PowerShell – Try/Catch/Retry

# try/catch/fix and continue $tries = 0 while ($tries -lt 2) {    try {      $tries++      $ErrorActionPreference=’Stop’      # code I am testing goes here – perhaps with a param argument that needs changing      $tries++    }   catch { #fixup code goes here      $ErrorActionPreference=’SilentlyContinue’ # and the loop will now…

0