1

I need a help

I have trouble to set a script in powershell that give DOMAIN adminsitrator rights to an User to an executable . Because I need to install a program in many desktops, plus I need to check if the program is already installed.

This seams to be easy but I know how to program in shell script not much powershell.

$SPAdmin = "DOMAIN\ADMIN" 
$Password="FooBoo"|ConvertTo-SecureString -AsPlainText -Force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $SPAdmin, $Password 

Get-WmiObject -Class Win32_Service -ComputerName "Server" -Filter "Name='ServiceName'" -Credential $Credential

$name = "CagService"

   if (Get-Service $name -ErrorAction SilentlyContinue)
    {   
     Write-Host "O Servico do Agente conhecido como $name ja esta Instalado na Maquina com Hostname: $env:computername"
     sleep 5
    }
    Else
    {
            $storageDir = $pwd
            $source = "https://source"
            $destination = "$storageDir\agent.exe"

            Invoke-WebRequest $source -OutFile $destination

            $exec = New-Object -com shell.application
            $exec.shellexecute($destination);
    }  
Daniel
  • 95
  • 4
  • 12
  • 2
    "that give adminsitrator rights to an executable" - executables don't have rights, *accounts* have rights. – Mathias R. Jessen Dec 12 '16 at 17:27
  • @MathiasR.Jessen's comment is entirely correct. I would add that if you are asking if it is possible to bypass the UAC prompt in script, the answer is "no, you can't." – Bill_Stewart Dec 12 '16 at 17:28
  • @Bill_Stewart, no I don't want to by pass, yes thanks friend users have rights not an executable, how to make an admin run an executable file from another account using powershell? – Daniel Dec 12 '16 at 17:32
  • Possible duplicate of [PowerShell: Running a command as Administrator](http://stackoverflow.com/questions/7690994/powershell-running-a-command-as-administrator) – Nick Dec 12 '16 at 18:47
  • If you are looking for running under a different account, you might want to use [PSexec from SysInternals](https://technet.microsoft.com/en-us/sysinternals/bb842062.aspx). – BenH Dec 12 '16 at 20:52

1 Answers1

1

Is there any reason that you can't simply do:

Start-Process powershell -Verb runAs

From a PS console? That launches a new ps window with admin privileges....

PowerShell: Running a command as Administrator

Community
  • 1
  • 1
Nick
  • 1,178
  • 3
  • 24
  • 36
  • Hi but I want as a Domain Administrator. – Daniel Dec 13 '16 at 11:52
  • Then you need to put in credentials. You can't use a domain admin account without putting in credentials and even if you save your DA password as a secure string, that string has to be saved on the computer that is using the credentials. – Nick Dec 13 '16 at 13:23
  • "but I want as a Domain Administrator" - why? – Bill_Stewart Dec 14 '16 at 18:31