Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a sudo-like command for Powershell
#
# Author: Tad DeVries
# Email: taddevries@gmail.com
# FileName: RunElevated.ps1
#
# Description:
# Creates a "sudo" like command to elevate another
# command to administrative level. This is used to
# simplify the CLI interaction and create a little
# home like feeling for the *nix users out there.
#
#
# Copyright (C) 2010 Tad DeVries
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# License Info: http://www.gnu.org/licenses/gpl-2.0.html
#
#
function RunElevated
{
param( [string]$Program=$(Throw "Please specify a program"), [string]$Arguments = $args )
$psi = new-object System.Diagnostics.ProcessStartInfo $Program;
$psi.Arguments = $Arguments;
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;
[System.Diagnostics.Process]::Start($psi);
<#
.SYNOPSIS
Runs a programs with elevated privilages.
.DESCRIPTION
Runs a programs with elevated privilages. Just like good old sudo in Linux
.INPUTS
Any program needing admin privilages to run.
.EXAMPLE
RunElevated notepad temp.txt
.EXAMPLE
sudo notepad temp.txt
.LINK
http://splunk.net
#>
}
##Set a simplified alias to mimic the *nix world
Set-Alias sudo RunElevated
##export module
Export-ModuleMember -Function * -Alias *
# SIG # Begin signature block
# MIIbaQYJKoZIhvcNAQcCoIIbWjCCG1YCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU9UDGOyXgFwGmaaSpDr1L3LNg
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N2+gANavcV1
# 0MaoViawRgQ8GEsKBpppgZ42FEaB/Gdw3XQp2zixDeprUwjApmLLMgKEM+QRBc7z
# KKnMzm7d1a3rh+rpnjfGwQpQ/DcPXDhnQDR5kP9Ua1jXJ9E4WZK54r8uduNH53ab
# /0IQA4VzLmRVZGNJYbTVuBED9lyvuirInRdpQffEaWX/hIbzZ6LsQTJSCAiFFd2m
# ed1j9Dg/9pfwUZHxsMM3Mx8jQKQjsqRBeEbr7y+xWevInATHRIrPk2nJ3EH0C1ai
# Rjc1dV+gWDPVwKMa4pYKjuba1NyEk5UqxkCgo2MxP3ZFglNUSVCqazxU3bhZxzgF
# 0z/0BELTIFiLaI/AaQ4a20/0fUBPI/DOmntPgyMKARQ0vP+cmuD9501uafE2XKXp
# mLsbW/jrA3TevaGCAX8wggF7BgkqhkiG9w0BCQYxggFsMIIBaAIBATBnMFMxCzAJ
# BgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjErMCkGA1UEAxMiVmVy
# aVNpZ24gVGltZSBTdGFtcGluZyBTZXJ2aWNlcyBDQQIQeaKlhfnRFUIT2bg+9raN
# 7TAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG
# 9w0BCQUxDxcNMTIxMDI3MDI0NzIxWjAjBgkqhkiG9w0BCQQxFgQUXnCk+bSu4yI4
# o9PxAfoni6sDiM0wDQYJKoZIhvcNAQEBBQAEgYCDsci8IWyhusLpwxebvqsETMgc
# 7OR6l4Jtgzj5hrg/mOoePUfr25hZHQn3HeqE47IYuDUeEL61u8FHT6RmRAhK1Fnh
# ys0jx1SXh7kMQkBgHvfNEoKIekGYzojUXC2XI+7kFnvbcvJrpx04Oi0ibVVd/Xi0
# N5OOiH7wuD9ONp0hrQ==
# SIG # End signature block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.