Skip to content

Instantly share code, notes, and snippets.

@ducke
ducke / ScriptWithFunction.tests.ps1
Created January 29, 2020 12:14 — forked from LawrenceHwang/ScriptWithFunction.tests.ps1
ScriptWithFunction.tests.ps1
Describe 'Unit testing the helper functions in self contained script' {
BeforeAll {
# Using AST to parse the function definitions from the self contained script.
# Then, save the script of the Pester test drive.
$FilePath = Join-Path -Path '.' -ChildPath 'ScriptWithFunction.ps1'
$ast = [System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$null, [ref]$null)
$functionDefinition = $ast.FindAll( {
param([System.Management.Automation.Language.Ast] $AstInput)
$AstInput -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
# Class methods have a FunctionDefinitionAst under them as well, but we don't want them.
@ducke
ducke / Invoke-SCCMRunScript.ps1
Created September 16, 2019 08:07 — forked from Robert-LTH/Invoke-SCCMRunScript.ps1
Simple script to use the new sccm feature called "Run Script". The builtin Invoke-CMScript does not accept parameters.
function Invoke-SCCMRunScript {
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$SiteServer,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Namespace,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
@ducke
ducke / PowerShellv4_DynamicKeyword.md
Created September 24, 2018 10:29 — forked from altrive/PowerShellv4_DynamicKeyword.md
Test code of PowerShell v4 Dynamic Keyword

Define DynamicKeyword

Define DynamicKeyword 'ExecTest'

Note: Don't copy&paste from following code. PowerShell SyntaxHighlighter remove some lines. Instead, use RAW view.

#Requires -Version 4.0
Set-StrictMode -Version Latest
##############################################
############## Script Info ###################
##############################################
## Created By : Dan Cook 2017 ########
##############################################
<#
Version Info :
0.1 - 25/05/2017 - Creates a graphvis diagram and accompanying DOT code file
for an SCCM application dependency tree, by querying the
@ducke
ducke / New-WPFMessageBox
Created August 25, 2017 08:16 — forked from SMSAgentSoftware/New-WPFMessageBox
PowerShell function to display a customizable WPF message box / window
Function New-WPFMessageBox {
# For examples for use, see my blog:
# https://smsagent.wordpress.com/2017/08/24/a-customisable-wpf-messagebox-for-powershell/
# Define Parameters
[CmdletBinding()]
Param
(
# The popup Content
@ducke
ducke / Import-CsvToMongo.ps1
Created August 16, 2017 19:19 — forked from Kieranties/Import-CsvToMongo.ps1
A quick and dirty way of getting data from a csv into MongoDB. Knocked together for #NHTG13
<#
.NOTES
You'll need the excellent C# driver: http://docs.mongodb.org/ecosystem/drivers/csharp/
#>
Add-Type -Path "c:\mongodb\bin\MongoDB.Bson.dll"
Add-Type -Path "c:\mongodb\bin\MongoDB.Driver.dll"
Function Import-CsvToMongo{
param($path, $dbUrl, $collection, $matchCol) #matchCol is used as a lookup to check if entry is to be added or updated
Function Load-ConfigMgrAssemblies {
Param(
$AdminConsoleDirectory = ($env:SMS_ADMIN_UI_PATH | Split-Path -Parent)
)
#Add-Type -Path "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\DcmObjectModel.dll"
$filesToLoad = "Microsoft.ConfigurationManagement.ApplicationManagement.dll","AdminUI.WqlQueryEngine.dll", "AdminUI.DcmObjectWrapper.dll","DcmObjectModel.dll","AdminUI.AppManFoundation.dll","AdminUI.WqlQueryEngine.dll","Microsoft.ConfigurationManagement.ApplicationManagement.Extender.dll","Microsoft.ConfigurationManagement.ManagementProvider.dll","Microsoft.ConfigurationManagement.ApplicationManagement.MsiInstaller.dll"
Set-Location $AdminConsoleDirectory
[System.IO.Directory]::SetCurrentDirectory($AdminConsoleDirectory)
@ducke
ducke / README.md
Created November 12, 2015 15:24 — forked from zenorocha/README.md
A template for Github READMEs (Markdown) + Sublime Snippet

Project Name

TODO: Write a project description

Installation

TODO: Describe the installation process

Usage

@ducke
ducke / git-random-tip.ps1
Created November 9, 2015 15:08 — forked from devlead/git-random-tip.ps1
PowerShell scrips that displays random GIT tips
(irm https://raw.githubusercontent.com/git-tips/tips/master/tips.json)|sort {random}|select -First 1|% {"$($_.title)`r`n$($_.tip)" }
@ducke
ducke / http_server.ps1
Created October 19, 2015 15:47 — forked from nobodyguy/http_server.ps1
Powershell HTTP server in background thread (could be easily killed)
$ServerThreadCode = {
$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add('http://+:8008/')
$listener.Start()
while ($listener.IsListening) {
$context = $listener.GetContext() # blocks until request is received
$request = $context.Request