Skip to content

Instantly share code, notes, and snippets.

@dfinke
dfinke / CFSBuddy.ps1
Created September 17, 2014 14:37
PowerShell v5.0 ConvertFrom-String Buddy - A GUI that helps you work with this new powerful cmdlet
#Requires -Version 5.0.9814.0
if(!($PSVersionTable.PSVersion.Major -ge 5 -and $PSVersionTable.PSVersion.Build -ge 9814)) {
"Sorry you need PSVersion 5.0.9814.0 or newer"
$psversiontable
return
}
Add-Type -AssemblyName presentationframework
@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'
@glapointe
glapointe / Load-CSOMProperties.ps1
Created March 31, 2015 20:28
Utility PowerShell function that facilitates the loading of specific properties of a Microsoft.SharePoint.Client.ClientObject object or Microsoft.SharePoint.Client.ClientObjectCollection object.
<#
.Synopsis
Facilitates the loading of specific properties of a Microsoft.SharePoint.Client.ClientObject object or Microsoft.SharePoint.Client.ClientObjectCollection object.
.DESCRIPTION
Replicates what you would do with a lambda expression in C#.
For example, "ctx.Load(list, l => list.Title, l => list.Id)" becomes
"Load-CSOMProperties -object $list -propertyNames @('Title', 'Id')".
.EXAMPLE
Load-CSOMProperties -parentObject $web -collectionObject $web.Fields -propertyNames @("InternalName", "Id") -parentPropertyName "Fields" -executeQuery
$web.Fields | select InternalName, Id
@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
}
@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
@davefunkel
davefunkel / Script-Template-WithCreds.ps1
Last active August 28, 2024 07:24
PowerShell Script Template with Saved Creds
<#
.SYNOPSIS
The synopsis goes here. This can be one line, or many.
This version of the template has inbuilt functions to capture credentials and store it securely for reuse
Avoids the need to have plaintext passwords in the script
.DESCRIPTION
The description is usually a longer, more detailed explanation of what the script or function does.
Take as many lines as you need.
@Jaykul
Jaykul / Mandelbrot.psm1
Last active December 26, 2023 11:41
ASCII Mandelbrots in the PowerShell console
using namespace System.Numerics
class Mandelbrot : System.Collections.IEnumerator {
# From the constructor?
# Sadly, PowerShell doesn't support optional parameters
[double]$HorizontalViewOffset = -0.5
[double]$VerticalViewOffset = 0
$Columns = 120
$Rows = 28
$ZoomViewDistance = 6.75
Function Out-JSONView {
[cmdletbinding()]
Param (
[parameter(ValueFromPipeline)]
[psobject]$InbutObject,
[int]$Depth = 2
@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`"'"
@Tiberriver256
Tiberriver256 / PowerShellNTFSStaticFileServer.ps1
Last active July 29, 2024 12:16
This script starts a small web server listening on localhost:8080 that will impersonate the authenticated user and serve static content. This means if they do not have NTFS permissions to the file they will get an access denied or a 404 file not found if they do not have NTFS access to list contents of the directory.
function Get-DirectoryContent {
<#
.SYNOPSIS
Function to get directory content
.EXAMPLE
Get-DirectoryContent -Path "C:\" -HeaderName "poshserver.net" -RequestURL "http://poshserver.net" -SubfolderName "/"