Skip to content

Instantly share code, notes, and snippets.

@lukesampson
lukesampson / runat.ps1
Last active April 29, 2024 22:07
A powershell script to replicate some of the `at` command for Windows Server 2012.
$usage = "usage: runat (time) (command)
e.g. runat 2am shutdown -r -f -c ""restart""";
function esc($s) { [regex]::escape($s) }
$t = $args[0] # time
if($args.length -gt 1) { # command
$c = $args[1..($args.length-1)] | % { if($_ -match '\s') { "`"$_`"" } else { $_ } }
@lukesampson
lukesampson / install.ps1
Last active December 18, 2015 11:59
Installs a powershell script, proof of concept for "scoop".
# 1. installs a powershell script to ~\appdata\local\scoop\[name]\[name].ps1
# 2. adds a stub to ~\appdata\local\scoop\bin, to avoid path pollution
# 3. makes sure ~\appdata\local\scoop\bin is in your path
function install($name, $url) {
$erroractionpreference = 'stop'
# helpers
function dl($url,$to) { (new-object system.net.webClient).downloadFile($url,$to) }
function env($name,$val) {
if($val) { [environment]::setEnvironmentVariable($name,$val,'User') } # set
@lukesampson
lukesampson / hello.ps1
Created September 5, 2013 04:51
A simple example for Scoop documentation.
$name = split-path (whoami) -leaf
"Hello, $name!"
@lukesampson
lukesampson / hello.json
Created September 5, 2013 06:06
A simple app manifest example for Scoop.
{
version: "2.0",
url: "https://gist.github.com/lukesampson/6446238/raw/hello.ps1",
bin: "hello.ps1"
}
write-host "checking..."
# check for apache
$apache = scoop which httpd
if($lastexitcode -ne 0) { 'Apache isn''t installed. run ''scoop install apache'''; return }
# check for php
$php = scoop which php
if($lastexitcode -ne 0) { 'PHP isn''t installed. run ''scoop install php'''; return }
# quick exec:
# iex (new-object net.webclient).downloadstring('https://gist.github.com/lukesampson/6725722/raw/sudo_diag.ps1')
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
"current user: $($id.name)"
$elevated = ([Security.Principal.WindowsPrincipal]($id)).isinrole("Administrators")
"elevated: $elevated"
$name = $id.name -replace '^[^\\]*\\', ''
$res = gwmi win32_groupuser | ? { $_.partcomponent -match "name=`"$name`"" }
@lukesampson
lukesampson / visualc2010_install.ps1
Last active May 27, 2018 09:00
Install script for Visual Studio 2010 (for use with Scoop).
param($dir)
write-host 'extracting msi...' -nonewline
start msiexec -arg '/a', "$dir\vs_setup.msi", '/qn', "TARGETDIR=`"$dir\tmp`"" -wait
cp $dir\tmp\* $dir -r -force
rm $dir\tmp -r -force
rm $dir\vs_setup.msi
rm $dir\vs_setup.cab
rm $dir\vs_expbsln_x64_enu.cab
{
"version": "0.0.1.z",
"url": "https://github.com/jkrehm/pshazz/archive/z.zip",
"extract_dir": "pshazz-z",
"bin": [ "bin\\pshazz.ps1" ],
"installer": { "file": "bin\\install.ps1" }
}
@lukesampson
lukesampson / sudo_debug.ps1
Last active November 15, 2019 03:32
Debug script for sudo.ps1 (psutils)
# to debug sudo problems.
# to download:
# (new-object net.webclient).downloadfile('https://gist.githubusercontent.com/lukesampson/9130445/raw/sudo_debug.ps1', "$pwd/sudo_debug.ps1")
# to test:
# ./sudo_debug.ps1 echo hi
if(!$args) { "usage: sudo <cmd...>"; exit 1 }
function is_admin {
write-host "DEBUG: is_admin"
$id = [security.principal.windowsidentity]::getcurrent()
@lukesampson
lukesampson / scoop-reinstall.ps1
Created May 31, 2016 23:22
Overwrites a bad Scoop install
#requires -v 3
# remote install:
# iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
$erroractionpreference='stop' # quit if anything goes wrong
# get core functions
$core_url = 'https://raw.github.com/lukesampson/scoop/master/lib/core.ps1'
echo 'initializing...'
iex (new-object net.webclient).downloadstring($core_url)