Skip to content

Instantly share code, notes, and snippets.

@bielawb
bielawb / Excel.psm1
Created March 13, 2015 04:31
Module to read Excel as if it was just XML. Needs work (e.g. some cleanup after data is read).
<#
List taken from SO answer:
http://stackoverflow.com/questions/4730152/what-indicates-an-office-open-xml-cell-contains-a-date-time-value
#>
$ExCellStyles = @{
0 = 'General'
1 = '0'
2 = '0.00'
3 = '#,##0'
@mattifestation
mattifestation / ConvertFromSID.ps1
Created May 14, 2017 15:57
Example of filtering off the Win32_AccountSID association class to convert a SID->User using only WMI
function ConvertFrom-SID {
param (
[Parameter(Position = 0, Mandatory = $True)]
[String]
[ValidateNotNullOrEmpty()]
$SID
)
$AccountSIDInstance = Get-CimInstance -ClassName Win32_AccountSID -Filter "Setting = 'Win32_SID.SID=`"$SID`"'"
@IISResetMe
IISResetMe / Get-ADUserPasswordExpiration.ps1
Last active July 10, 2017 20:39
Password expiration function that takes fine-grained password policies into account
#Requires -Modules ActiveDirectory
function Get-ADUserPasswordExpiration
{
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[Alias('DistinguishedName')]
[Microsoft.ActiveDirectory.Management.ADUser[]]$Identity
)
@IISResetMe
IISResetMe / bad.ps1
Last active September 25, 2017 23:32
Middle Management Reporting in PowerShell
$Properties = 'employeeID'
# Retrieve all workers with their "manager" attribute
Get-ADUser -Filter "title -like '*worker*'" -Properties @('manager';$Properties) |ForEach-Object {
# Iterate over workers, retrieve each workers manager individually
[pscustomobject]@{
Worker = $_
Manager = Get-ADUser -Identity $_.manager -Properties $Properties -ErrorAction SilentlyContinue
}
}
@duffney
duffney / Create-PullServerModule.ps1
Last active June 11, 2018 15:00
Create-PullServerModule.ps1
$source = "C:\LabResources\xTimeZone"
$destination = "C:\temp"
$Version = (Get-ChildItem -Path $source -Depth 1).Name
$ResoureName = (Get-ChildItem -Path $source -Depth 1).Parent.Name
$ModuleName = $ResoureName+'_'+$Version
New-Item -Path ($destination+'\'+$ModuleName) -ItemType Directory
@mgreenegit
mgreenegit / WSManTrust.psm1
Last active December 3, 2020 22:55
Simple set of commands to maintain the WSMan trusted hosts list
function Get-WSManTrust {
(Get-Item -Path WSMan:\localhost\Client\TrustedHosts | % Value).split(',')
}
function New-WSManTrust {
param(
[string]$hostname
)
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value $hostname -Concatenate -Force
}
@JustinGrote
JustinGrote / Get-AzRetailPrice.ps1
Created November 2, 2020 01:45
Azure Retail Pricing API Proof of Concept
function Get-AzSpotPrice {
[CmdletBinding()]
param (
#VM SKU (e.g. Standard_F8s)
[String]$Sku,
#Azure Region (e.g. brazilsouth)
[String]$Region,
#ODATA filter to use on the data
[String]$Filter,
#Maximum number of records to retrieve, or specify 'Unlimited' for all records. Defaults to 100. This behaves like the Exchange Cmdlets
@stefanstranger
stefanstranger / parallel-pester-tests.ps1
Last active May 16, 2021 19:58
Run Pester Tests parallel
# Example code of running multiple Pester test in parallel and merging the result into one NUnitReport Test Report file
#region Run Pester Test scripts in parallel
$job = Get-ChildItem -Path "./tests" -Filter "Demo*"
| ForEach-Object -Parallel {
Invoke-Pester -Path $_ -PassThru
} -ThrottleLimit 10 -AsJob
$Results = ($job | Wait-Job | Receive-Job -Keep)
#endregion
@markekraus
markekraus / ConvertKMSEncryptedStrings.ps1
Created February 18, 2018 19:41
PowerShell Functions to convert a string to a base64 representation of the KMS encryoted string and to convert back to an unencrypted string
function ConvertTo-Base64KMSEncryptedString {
[CmdletBinding()]
param (
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[String[]]
$String,
@dfinke
dfinke / Open-GHWebEditor.ps1
Last active August 17, 2021 12:42
Opens the GitHub web editor on a repo
function Open-GHWebEditor {
<#
.SYNOPSIS
Opens the GitHub web editor on a repo.
.EXAMPLE
Open-GHWebEditor powerShell/powerShell
#>
param(
[Parameter(Mandatory)]