param (
[string] $user
)
function SuPowershell($domain, $user, $params=""){
$SuAccount = get-credential "$domain\$user"
if (!$SuAccount){
return
}
$StartInfo = new-object System.Diagnostics.ProcessStartInfo
$StartInfo.FileName = "$pshome\powershell.exe"
$StartInfo.Domain = split-path $SuAccount.UserName
$StartInfo.UserName = split-path -leaf $SuAccount.UserName
$StartInfo.Password = $SuAccount.Password
$StartInfo.LoadUserProfile = $true
$StartInfo.UseShellExecute = $false
$StartInfo.Arguments = $params
$StartInfo.WorkingDirectory = (get-location).Path
[System.Diagnostics.Process]::Start($StartInfo)
}
$admin = "Administrator"
$thisScript = $myInvocation.MyCommand.Definition
$powershell = "$pshome\powershell.exe"
$group="Administrators"
if (!$user){
$domain = $env:UserDomain
$currentUser = $env:Username
SuPowershell $env:ComputerName $admin "`"& `'$thisscript`'
$domain\$currentUser`""
}
else {
$runasdomain = $(split-path $user)
$runasUser = $(split-path -leaf $user)
#Running as admin
net localgroup $group $user /ADD
SuPowershell $runasdomain $runasUser
net localgroup $group $user /DELETE
}
--
greetings
dreeschkind
"Alex K. Angelopoulos [MVP]" wrote:
> Can you repost with a .txt addition on the end of that extension? It appears
> to be automatically blocked by OE, and I'm not quite up to base64decoding
> the message source this morning. 
>
>
> "Staffan Gustafsson" <staffan._less_spam_gustafsson@home.se> wrote in
> message news:eCTgM9t4GHA.3556@TK2MSFTNGP02.phx.gbl...
> > Hi,
> >
> > Here's a dirty version of a powershell variant of Aaron Margosis
> > MakeMeAdmin.cmd
> > (http://blogs.msdn.com/aaron_margosis...4/193721.aspx).
> >
> > It uses get-credential and Process.Start instead of runas.
> >
> > All suggestions for improvements are welcome.
> >
> > Regards,
> >
> > /Staffan
> >
> >
>
>
>