Skip to content

Instantly share code, notes, and snippets.

@CosmosKey
CosmosKey / Launch program remotely through CIM over DCOM.ps1
Created February 21, 2017 12:33
Launch program remotely through CIM over DCOM
$cimSessionOption = New-CimSessionOption -Protocol Dcom
$cimSession = New-CimSession -ComputerName $env:computername -SessionOption $cimSessionOption
Invoke-CimMethod -CimSession $cimSession -ClassName win32_process -methodname Create -Arguments @{
commandline = "powershell.exe -executionpolicy bypass -file \\$env:computername\c`$\ps\test.ps1"
}
@CosmosKey
CosmosKey / Get-ADGroupMemberSamAccountName
Created February 27, 2018 23:54
Get-ADGroupMemberSamAccountName
Function Get-ADGroupMemberSamAccountName {
param(
[Parameter(Mandatory,ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[string]$GroupName
)
process {
$name = $GroupName
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$dc = $domain.FindDomainController([System.DirectoryServices.ActiveDirectory.LocatorOptions]::WriteableRequired)
While ( $True ) { $PSise.Options.Zoom = 100 + 10 * [math]::sin( (Get-Date).TimeOfDay.TotalSeconds ); Sleep -Milliseconds 40 }
@CosmosKey
CosmosKey / AbortShutdown.ps1
Created April 22, 2019 20:47
Abort Windows Shutdown
$definition = @'
using System;
using System.Runtime.InteropServices;
public class W32ShutdownUtil {
[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool AbortSystemShutdown(String machineName);
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
@CosmosKey
CosmosKey / GetHelpRightForPSTypeNames.ps1
Created November 18, 2020 09:55
How to Get Help Right For PSTypeNames
#
# How to get help right for an array of PSTypeNames
#
# Awesome function to get some random stuff
# The important thing is that we get objects with an added PSTypeName of 'Stuff'
Function Get-Stuff {
[cmdletbinding()]
param(
$tmpFile = New-TemporaryFile
@"
DisplayName,Phone
Johan Akerstrom,0721234567
Test Tester,0711234567
"@ | Set-Content $tmpFile
#requires -version 5.1
@CosmosKey
CosmosKey / Import Base64 cert into cert store
Created May 25, 2021 08:11
Import Cert without touching the file system.
# Orginal Cert
$base64CertAsGetContentImported = @(
'-----BEGIN CERTIFICATE-----'
'MIIDPjCCAiagAwIBAgIQQuZ95xvR1p5DHeDuOzxbPzANBgkqhkiG9w0BAQsFADAb'
'MRkwFwYDVQQDDBB3d3cuZmFicmlrYW0uY29tMB4XDTIxMDUyNTA3MzAwNFoXDTIy'
'MDUyNTA3NTAwNFowGzEZMBcGA1UEAwwQd3d3LmZhYnJpa2FtLmNvbTCCASIwDQYJ'
'KoZIhvcNAQEBBQADggEPADCCAQoCggEBANs51YbaCyGdgduRTKAwqd2R9z0BwfH1'
'RuBzWP4imFNjvgmJDR4tII3ESng3udp3QqBu8ArdBVAZL0a5w+lJ9uhC8vD+pDGb'
'dtEqBi5fSzEMSGahVT+P8VqB2myVah9Ab6kuz5dGjtkIX7aoI3yId3Ji3lU8gtbv'
'U8Az5mxqhsDajl9BuUJCtVr02+i4WmbSLI3nzxFDXYJjJIVvrS/yxTzH7nuRud+d'
@CosmosKey
CosmosKey / PowerShellGet - Setup Local Repo.ps1
Created February 16, 2017 12:34
PowerShellGet - Setup a local repository demo
###############################################################
#
# A quick look at setting up local PowerShellGet repositories
#
###############################################################
#
# Find and install a module from PSGallery