Run powershell script with domain admin rights

Tulik23 K 66 Reputation points
2022-03-25T16:06:57.35+00:00

Hi

i need to run a powershell script with domain admin user/pass
the script will take own on a folder (as admin) and give a the user rights ( $User = Read-Host -Prompt 'Input the user name')

this is the script :

$User = Read-Host -Prompt 'Input the user name'
write-Host $user
takeown /f i:\$user\videos /r /d y
icacls i:\$user\videos /grant administrators:F /t

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,463 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,906 Reputation points
    2022-03-25T18:52:55.86+00:00

    Put your code in a script block and then use that script block in an Invoke-Command. Add the -Credential parameter to the Invoke-Command and provide the user/password for a domain admin user.

    0 comments No comments