Skip to content

Instantly share code, notes, and snippets.

@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)
@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()
{
"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 / 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
# 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`"" }
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 }
@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"
}
@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 / 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 / runat.ps1
Last active August 21, 2020 13:16
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 { $_ } }