Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
mattmcnabb / Set-GpoStatus.ps1
Last active January 5, 2024 01:04
Set the status of a Group Policy Object with Powershell
Function Set-GPOStatus
{
<#
.Synopsis
Set the status of a Group Policy Object
.Description
Sets the status of one or more Group Policy objects.
.Example
PS C:\> Get-Gpo MyGPO | Set-GPOStatus -Status AllSettingsEnabled
.Example
@mattmcnabb
mattmcnabb / Start-ControlPanelApplet.ps1
Created December 14, 2018 18:50
Launch windows control panel applets from PowerShell
$ControlPanelApplets = [ordered]@{
"Add a Device wizard" = "$env:windir\System32\DevicePairingWizard.exe"
"Add Hardware wizard" = "$env:windir\System32\hdwwiz.exe"
"Add a Printer wizard" = "rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter"
"Administrative Tools" = "control.exe /name Microsoft.AdministrativeTools"
"AutoPlay" = "control.exe /name Microsoft.AutoPlay"
"Backup and Restore" = "control.exe /name Microsoft.BackupAndRestoreCenter"
"BitLocker Drive Encryption" = "control.exe /name Microsoft.BitLockerDriveEncryption"
"Color and Appearance" = "explorer shell:::{ED834ED6-4B5A-4bfe-8F11-A626DCB6A921} -Microsoft.Personalization\pageColorization"
"Color Management" = "control.exe /name Microsoft.ColorManagement"
@mattmcnabb
mattmcnabb / TransformTest1.psm1
Last active November 14, 2019 20:56
Can't quite get these transforms working...
# this works, but only if I import with using
class StringTransformAttribute : System.Management.Automation.ArgumentTransformationAttribute
{
[object] Transform([System.Management.Automation.EngineIntrinsics]$EngineIntrinsics, [object]$InputData)
{
return "a different string"
}
}
function Test-StringTransform
@mattmcnabb
mattmcnabb / Get-JsonWhois.ps1
Created July 8, 2019 13:42
Get IP Address WhoIs Info
function Get-JsonWhois
{
[CmdletBinding(DefaultParameterSetName = "ip")]
param
(
[Parameter(Mandatory, ParameterSetName = "ip")]
[string]
$IPAddress,
[Parameter(Mandatory, ParameterSetName = "domain")]
@mattmcnabb
mattmcnabb / NamedParameters.ps1
Last active July 5, 2019 15:52
New up an object with default constructor
# default constructor - has no parameters
# method 1 - new and then set properties
$Configuration = [Foo.ConfigurationObject]::new()
$Configuration.Domain = $DomainName
$Configuration.Token = $Token
# method 2 - add properties via New-Object
$Configuration = New-Object Foo.ConfigurationObject -Property @{
Domain = $DomainName
@mattmcnabb
mattmcnabb / PoshRS.ps1
Created September 30, 2016 02:45
Trouble with array in PoshRSJob
# set up a simple array
$Items = @(
[PSCustomObject]@{Name = 'Item1'; SomeProperty = "1"},
[PSCustomObject]@{Name = 'Item2'; SomeProperty = "2"},
[PSCustomObject]@{Name = 'Item3'; SomeProperty = "3"}
)
### enumerate a property of the objects passed in via -ArgumentList
# the output here is always '2'
@mattmcnabb
mattmcnabb / Add-TaskbarItem.ps1
Created March 16, 2016 01:23
Pin or unpin applications to/from the taskbar
function Add-TaskbarItem
{
<#
.SYNOPSIS
Adds or removes items from a user's taskbar
.DESCRIPTION
Adds or removes items from a user's taskbar. Supports pinning of multiple items using the pipeline.
.PARAMETER Action
@mattmcnabb
mattmcnabb / TermColors.ps1
Created October 30, 2018 19:25
PS Terminal Theme Colors
# desktop
"terminal.background": "#012456",
"terminal.foreground": "#F5F5F5"
# core
"terminal.background": "#141A25",
"terminal.foreground": "#F5F5F5"
@mattmcnabb
mattmcnabb / TruncateString.ps1
Last active October 23, 2018 13:51
Add a Truncate method to system.string
$Script = {
param([int]$MaxLength)
switch ($this)
{
{[string]::IsNullOrEmpty($_)} {$this; break}
{$_.Length -le $MaxLength} {$this; break}
default {$_.SubString(0, $MaxLength)}
}
}
function ConvertFrom-RGB
{
param
(
[Parameter(Mandatory)]
[ValidateCount(3,3)]
[Byte[]]
$RGB
)