Share via

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 for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Rich Matheisen 48,116 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.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.