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

PowerShell - DSC Environment Analyser (DSCEA)

Awesome! An  open source release of DSC Environment Analyzer (DSCEA), a PowerShell module that uses the declarative nature of Desired State Configuration to scan systems in an environment against a defined reference MOF file and generate compliance reports as to whether systems match the desired configuration. For more information, check out: https://blogs.technet.microsoft.com/ralphkyttle/2017/03/21/introducing-dscea/ https://github.com/Microsoft/DSCEA https://www.powershellgallery.com/packages/DSCEA  

2

DSC WebDownloadManagerGetActionFailed event id 4252

WebDownloadManagerGetActionFailed  event id 4252 C:\ Update-DscConfiguration -CimSession ms2 -Wait -Verbose VERBOSE: Perform operation ‘Invoke CimMethod’ with following parameters, ”methodName’ = PerformRequiredConfigurationChecks,’className’ = MSFT_DSCLocalConfigurationM anager,’namespaceName’ = root/Microsoft/Windows/DesiredStateConfiguration’. VERBOSE: An LCM method call arrived from computer MS2 with user sid S-1-5-21-3841426147-920288206-1542301449-500. VERBOSE: [MS2]:                            [] Executing Get-Action with configuration ‘s checksum: 666345C3DEE430EF11DBE636BB2BDD373457A9783F8B73AD64FA7316742EC8E9. VERBOSE: [MS2]:                            [] Executing Get-Action with…

0

PowerShell - native on Ubuntu

# all the things I did when installing DotNetCore and PowerShell for Linux onto an Ubuntu server #login and install various odds-and-ends sudo apt-get install lynx sudo apt-get install emacs sudo apt-get install libunwind8 libicu55 sudo apt-get install firefox sudo apt-get update # install the hyper-v aware kernel stuff (may not need it, but what…

0

PowerShell - Out-ColourMatch

#Out-ColourMatch.ps1 Set-StrictMode -Version Latest function Out-ColourMatch { <# .Synopsis Outputs coloured matches from Select-String .Description Outputs the matched string, with the match section(s) highlighted in colour. .INPUTS a [Microsoft.PowerShell.Commands.MatchInfo] object. .OUTPUTS None. Write-Host displays the colourised string. .Example Get-Content .\LoremIpsum.txt | Select-String -Pattern ‘dolor’ -AllMatches | Out-ColourMatch .Example $b = Get-Content .\LoremIpsum.txt | Select-String -Pattern…

1

Azure CLI - the cross-platform way

After having a ton of fun with raw PowerShell in both ASM (‘Classic’) and the far more sensible ARM models, I then discovered the stunning simplicity of JSON templates. See the Quickstart gallery here: https://github.com/Azure/azure-quickstart-templates Combining the templates and DSC gives ‘infrastructure as code’ in a surprisingly simple/elegant way. However this week I spent time…

2

PowerShell - Analogue Clock

# analogue-clock.ps1 # Set-StrictMode -Version latest Add-Type -AssemblyName System.Drawing Add-Type -AssemblyName System.Windows.Forms $DegreesToRadians = [Math]::PI/180 $PSicon = [Drawing.Icon]::ExtractAssociatedIcon((Get-Command -Name powershell).Path) ################################# function Initialize-Clock() { # create the form to display the clock $script:form = New-Object  -TypeName Windows.Forms.Form $script:form.Icon = $PSicon $script:form.Text = ‘Analogue Clock’ $script:form.Height = 700 $script:form.Width = $form.Height $script:form.BackColor=[Drawing.Color]::White $script:form.Location.X = 1000 $script:form.TransparencyKey…

1

Azure - ARM replacing ASM in Azure PowerShell

What Is Switch-AzureMode And Why Are We Deprecating It? https://github.com/Azure/azure-powershell/wiki/Deprecation-of-Switch-AzureMode-in-Azure-PowerShell

1

Windows - what version of PS is on the machines?

function GET-PSVERSIONINFO ([string[]] $TargetComputers) {   $HKLM = [Microsoft.Win32.RegistryHive]::LocalMachine  $PowerShellRegistry=”SOFTWARE\Microsoft\PowerShell”  $KeyItem = “\PowerShellEngine”  $Version = “PowerShellVersion”    $OldErrorActionPreference = $ErrorActionPreference  $ErrorActionPreference = “SilentlyContinue”#  if I cannot connect, don’t show the error, just continue onto the next one.   foreach ($computer in $TargetComputers)  {    $available = Test-Connection -ComputerName $computer -Quiet -Count 1    if ($available)  {     $psVersions=$null    …

0

SharePoint Web Services GUIDs - named

I’m always forgetting this command to translate those silly GUID services into text which is understandable. So here it is, where we can all find it. Get-SPServiceApplication | sort Id | FT -property Id, DisplayName -AutoSize

1