Skip to content

Instantly share code, notes, and snippets.

@jborean93
jborean93 / Runas.ps1
Created June 2, 2021 20:27
Creates a process running as SYSTEM
. $PSScriptRoot\Start-ProcessEx.ps1
Add-Type -Namespace Runas -Name NativeMethods -UsingNamespace @(
'Microsoft.Win32.SafeHandles',
'System.ComponentModel',
'System.Security.Principal'
) -MemberDefinition @'
[DllImport("Advapi32.dll", EntryPoint = "DuplicateTokenEx", SetLastError = true)]
private static extern bool NativeDuplicateTokenEx(
SafeHandle hExistingToken,
@Jaykul
Jaykul / About Batch and PowerShell.md
Last active July 28, 2024 04:33
Executable PowerShell (wrap a ps1 and name it cmd)

This is always my answer to all those "compile your .ps1" solutions that are floating around. Why would you wrap your PowerShell in an exe and some custom host?

Just paste this header on the top of your PowerShell script, and then before you share it, rename it with the .cmd extension. While you're writing, it's a nice syntax-highlighted PowerShell script, and when you rename it, *poof* it's double-clickable. Drop it in the PATH and you can execute it from the Run dialog or from PowerShell, batch, whatever.

Because there are still people around who actually use CMD, I've updated it to show how to handle passing parameters.

A couple of notes:

  1. It runs with ExecutionPolicy unrestricted because if you're still using CMD you probably haven't configured your ExecutionPolicy
  2. It uses -NoProfile to make sure the environment is the same on everyone's PC...
  3. It only creates function :: {} because that allows us to ignore the :: on the first line
@indented-automation
indented-automation / Get-FileEncoding.ps1
Last active November 1, 2022 19:56
Signature-based encoding detection
using namespace System.Collections.Generic; using namespace System.Linq
function Get-FileEncoding {
<#
.SYNOPSIS
Attempt to determine a file type based on a BOM or file header.
.DESCRIPTION
This script attempts to determine file types based on a byte sequence at the beginning of the file.
If an identifiable byte sequence is not present the file type cannot be determined using this method.
#requires -Version 3.0
<#
.SYNOPSIS
My Veeam Report is a flexible reporting script for Veeam Backup and
Replication.
.DESCRIPTION
My Veeam Report is a flexible reporting script for Veeam Backup and
Replication. This report can be customized to report on Backup, Replication,