Skip to content

Instantly share code, notes, and snippets.

@trondhindenes
trondhindenes / usersearch.ps1
Last active May 17, 2017 14:54
Function for verifying local and domain users
Function UserSearch
{
Param ([string]$AccountName)
#Check if there's a realm specified
if ($AccountName.Split("\").count -gt 1)
{
if ($AccountName.Split("\")[0] -eq $env:COMPUTERNAME)
{
$IsLocalAccount = $true
}
@trondhindenes
trondhindenes / win_acl.ps1
Last active August 29, 2015 14:24
proposed win_acl
#!powershell
# This file is part of Ansible
#
# Copyright 2015, Phil Schwartz <[email protected]>
#
# 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.
#
- name: Wait for windows reboot
# when: pending_reboot_output.pending_reboot == true
shell: 'if [[ -n $(curl -s -f -k --header "Content-Type: application/soap+xml;charset=UTF-8" --header "WSMANIDENTIFY: unauthenticated" https://thansiblewin01.ansib.le:5986/wsman --data "<s:Envelope xmlns:s=http://www.w3.org/2003/05/soap-envelope xmlns:wsmid=http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd><s:Header/><s:Body><wsmid:Identify/></s:Body></s:Envelope>" || true) ]]; then curl -s -f -k --header "Content-Type: application/soap+xml;charset=UTF-8" --header "WSMANIDENTIFY: unauthenticated" https://thansiblewin01.ansib.le:5986/wsman --data "<s:Envelope xmlns:s=http://www.w3.org/2003/05/soap-envelope xmlns:wsmid=http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd><s:Header/><s:Body><wsmid:Identify/></s:Body></s:Envelope>" || true ;else echo "nothing returned" ;fi'
register: result2
until: result2.stdout.find("http://www.w3.org/2003/05/soap-envelope")
retries: 10
delay: 10
delegate_t
@trondhindenes
trondhindenes / downloadurl.txt
Created August 19, 2015 16:27
Windows Server 2016 TP3 download URL
http://care.dlservice.microsoft.com/dl/download/7/3/C/73C250BE-67C4-440B-A69B-D0E8EE77F01C/10514.0.150808-1529.TH2_RELEASE_SERVER_OEMRET_X64FRE_EN-US.ISO
#Release when less than 4 moves are in progress
Function WaitForMoves
{
Do {
$moves = Get-moverequest | Get-moverequeststatistics | where {$_.StatusDetail -ne "COmpleted"}
if (($moves.count) -gt 3)
{
$movescount = $moves.count
Write-Progress -Activity "Moving $movescount" -Status "Moving $movescount" -PercentComplete 100
Start-sleep -seconds 10
@trondhindenes
trondhindenes / test-get-AnsibleParam.ps1
Created October 1, 2015 20:21
My test scripts for get-AnsibleParam
Set-StrictMode -Version 2
$params = "" | Select Firstname, Lastname, ensure
$params.Lastname = "Hindenes"
$params.Ensure = "present"
$returnobj = ""
. "D:\trond.hindenes\Documents\Scripts\Ansible\fork\trondhindenes\ansible\lib\ansible\module_utils\powershell.ps1"
#simple - should succeed
Get-AnsibleParam -obj $params -name Firstname
#Use alias
@trondhindenes
trondhindenes / Unzip-file.ps1
Created October 4, 2015 09:51
Unzips file using .net 4.5 with fallback to COM
function Unzip-File {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[ValidateScript({
If ((Test-Path -Path $_ -PathType Leaf) -and ($_ -like "*.zip")) {
$true
}
@trondhindenes
trondhindenes / ExecuteSelfAsScheduledTask.ps1
Created October 4, 2015 10:43
Script that will execute itself as a scheduled task
Function Exit-Json($obj)
{
# If the provided $obj is undefined, define one to be nice
If (-not $obj.GetType)
{
$obj = New-Object psobject
}
echo $obj | ConvertTo-Json -Compress -Depth 99
Exit
@trondhindenes
trondhindenes / AnsibleModuleWithAsync.ps1
Created October 4, 2015 13:11
Example module which uses scheduled jobs to invoke
#!powershell
# This file is part of Ansible.
#
# Copyright 2015, Trond Hindenes <[email protected]>
#
# 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 / AnsibleModuleWIthAsyncAndAlternateCreds.ps1
Created October 4, 2015 14:23
Example of a module supporting using a scheduled job with support for alternate credentials
#!powershell
# This file is part of Ansible.
#
# Copyright 2015, Trond Hindenes <[email protected]>
#
# 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.
#