Skip to content

Instantly share code, notes, and snippets.

@trondhindenes
trondhindenes / PowerShell Workflow paralell with throttle limit.ps1
Last active January 7, 2019 10:25
PowerShell Workflow paralell with throttle limit
workflow paralleltest
{
$a = 1..10
#Divide the 10 iterations into 3 (+1) blocks
foreach -parallel -throttlelimit (($a.count)/3) ($b in $a)
{
Write-Output $b
}
#A hashtable converted into a json string can be converted back to hashtable like so:
#Create a hashtable, convert to json
$hash = @{"Name1"="Value";"Name2"="Value2"}
$json = $hash | ConvertTo-Json
#Take the json string and convert it back:
$newobject = $json | ConvertFrom-Json
$newhash = @{}
foreach ($prop in $newobject.psobject.Properties)
workflow set-MITPrestageADComputer
{
Param (
[String]$CompName,
[string]$OU,
$Credential
)
Write-Output "Prestaging computer $CompName, OU $OU"
@trondhindenes
trondhindenes / WorkflowFail2.ps1
Last active August 29, 2015 14:02
WorkflowFail2
#Replace PSComputerName with a remote host
workflow FooNoError
{
param($CompName)
InlineScript {
$compName = $using:compName;
"Got $compName"
} -PSComputerName trondcloudDC
}
@trondhindenes
trondhindenes / configure-ansibletarget.ps1
Last active March 5, 2020 13:05
Configure Windows 2008R2/2012/2012R2 for SSL-based remoting
Param (
[string]$SubjectName = $env:COMPUTERNAME,
[int]$CertValidityDays = 365,
$CreateSelfSignedCert = $true
)
#region function defs
Function New-LegacySelfSignedCert
{
$Folders = get-childitem *db* -path "D:\MDB" -Recurse
foreach ($folder in $folders)
{
$DBName = $folder.Name
$ExchangeServer = $DBName.split("-")[0]
$LogFolderPath = $folder.Fullname.Replace("DB","LOG")
$edbfilepath = "$($folder.FullName)\$DBName.edb"
if (!(get-mailboxdatabase $DBName -erroraction 0))
{
#!powershell
# This file is part of Ansible.
#
# Copyright 2014, Trond Hindenes <trond@hindenes.com> and others
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@trondhindenes
trondhindenes / CheckPendingReboot2012.ps1
Created September 12, 2014 09:16
Check for pending reboot using the servermanager namespace
# Check if reboot is required. The MSFT_ServerManagerTasks provider is missing on client SKUs
$featureData = invoke-wmimethod -EA Ignore -Name GetServerFeature -namespace root\microsoft\windows\servermanager -Class MSFT_ServerManagerTasks
if($featureData -and $featureData.RequiresReboot)
{
Write-Verbose "Computer needs a reboot"
}
@trondhindenes
trondhindenes / ChildRunbookPublishFail.ps1
Created September 16, 2014 09:34
Description of a situation where a runbook will fail to run, even if the necessary "child runbook" is in place
#Configure the environment
$smawebserviceurl = "https://trondcloud-cs.cloudapp.net"
$smacreds = get-credential
#Set up two test runbooks, one referenced by the other (testwf1 references testwf2)
$TestWF1 = @"
workflow testwf1
{
@trondhindenes
trondhindenes / publish-SMAv2.ps1
Last active August 29, 2015 14:06
SMA things
Function Process-RunbookFolder
{
Param (
$Path,
[switch]$recurse
)
$allwfs = get-childitem -Path $Path -Recurse:$recurse
$Global:referencelist = New-Object System.Collections.ArrayList
[System.Collections.ArrayList]$Global:ToProcessList = $allwfs | select -ExpandProperty Fullname
$Global:DoneProcessList = New-Object System.Collections.ArrayList