Skip to content

Instantly share code, notes, and snippets.

@alx9r
alx9r / cimv2_dell_classname_listing.txt
Created October 20, 2015 19:57
root\cimv2\dell CIM classname listing from a 12th Generation Dell PowerEdge Server running OMSA version 7.4
gwmi -Namespace 'root\cimv2\dell' -list
NameSpace: ROOT\cimv2\dell
Name Methods Properties
---- ------- ----------
__SystemClass {} {}
__thisNAMESPACE {} {SECURITY_DESCRIPTOR}
Describe 'DSC Health' {
It 'KB3176934 is not installed' {
# https://blogs.msdn.microsoft.com/powershell/2016/08/23/powershell-dsc-broken-in-kb3176932/
$r = Get-Hotfix -Id KB3176934 -ea SilentlyContinue
$r | Should beNullOrEmpty
}
}
PS C:\> Trace-Command ParameterBinding { 'string' | Test-Discrimination } -PSHost
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Test-Discrimination]
DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL cmd line args [Test-Discrimination]
DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Test-Discrimination]
DEBUG: ParameterBinding Information: 0 : BIND arg [] to parameter [String]
DEBUG: ParameterBinding Information: 0 : Executing DATA GENERATION metadata:
[System.Management.Automation.ArgumentTypeConverterAttribute]
DEBUG: ParameterBinding Information: 0 : result returned from DATA GENERATION:
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String]
DEBUG: ParameterBinding Information: 0 : Parameter and arg types the same, no coercion is needed.
@alx9r
alx9r / File.Tests.ps1
Created October 28, 2016 18:38
Proof of concept for directly invoking the built-in DSC File Resource.
$record = @{}
$guid = [guid]::NewGuid().Guid
$tempPath = "$([System.IO.Path]::GetTempPath())FileResourceTest"
Describe 'File' {
Context 'setup' {
$fqClassName = @{
Namespace = 'root/microsoft/windows/DesiredStateConfiguration'
ClassName = 'MSFT_FileDirectoryConfiguration'
@alx9r
alx9r / moduleReloading.Tests.ps1
Last active November 29, 2016 17:09
Pester test demonstrating [Remove-Module;] Import-Module does not always reload modules.
$guid = '2282bfa0-cfdc-4ee5-a7a4-7aca5b33dc9f'
$workingFolderPath = "$([System.IO.Path]::GetTempPath())$guid"
$moduleContents = [ordered]@{
NoClasses = @{
Root = @'
Import-Module "$PSScriptRoot\Sub.psm1" -Args $Args
$passedArgs = $Args
function Get-PassedArgsRoot1 { $passedArgs }
function Get-PassedArgsRoot2 { $passedArgs }
Import-Module Pester
Import-Module AzureRM.Resources
Get-Command New-AzureRmResourceGroupDeployment | % ModuleName
[string](Get-Module AzureRM.Resources).Version
$PSVersionTable
Push-Location (Get-Module Pester).ModuleBase
$allVersions = git tag |
% {
@alx9r
alx9r / mockScopeDiff.Tests.ps1
Last active August 3, 2017 16:36
Tests summarizing scope-related differences for mocks between Pester 3 and 4
$guid = [guid]::NewGuid().Guid
$guidFrag = $guid.Split('-')[0]
$h = @{}
$h.MyInvocation = $MyInvocation
$directlyInvoked = -not [bool]$h.MyInvocation.Line
$h.TempTestScript = "$([System.IO.Path]::GetTempPath())\$guidFrag.Tests.ps1"
function Set-PesterVersion
{
[CmdletBinding()]
Add-Type @"
public class NullsafeString : System.IEquatable<string>,System.IConvertible
{
public string Value = null;
public NullsafeString(string v = null)
{
Value = v;
}
New-Module m {
function SomeScriptblockInvoker {
param
(
[Parameter(Position = 1)]
[scriptblock]
$Scriptblock,
[Parameter(ValueFromPipeline)]
$InputObject
@alx9r
alx9r / app.cs
Created October 11, 2017 16:53
Task<TResult>.Result throws exception
using System;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class Thrower
{
public string Throw()
{
throw new System.Exception("some exception");