"Staffan Gustafsson" <staffan._less_...@home.se> wrote in
message news:eCTgM9t4...@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> Here's a dirty version of a powershell variant of Aaron Margosis
> MakeMeAdmin.cmd
> (http://blogs.msdn.com/aaron_margosis/archive/2004/07/24/193721.aspx).
>
> It uses get-credential and Process.Start instead of runas.
>
> All suggestions for improvements are welcome.
>
> Regards,
>
> /Staffan
>
>
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
You could also have temporarily turned blocking off (tools > options >
security).
Jacques