Advertisement
techjoe

Run Section of System script as user

Mar 7th, 2023 (edited)
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Get the RunAsUser Module if not installed
  2. if (Get-Module -ListAvailable -Name RunAsUser) {
  3.        
  4.         Write-Host "RunAsUser Module is already installed. Continuing...."
  5.         Import-Module RunAsUser
  6.     } else {
  7.         Write-Host "RunAsUser was not installed. Installing it now."
  8.         Install-Module RunAsUser -Force
  9.         Import-Module RunAsUser
  10.     }
  11.  
  12. Update-Module RunAsUser
  13.  
  14. $scriptblock = {
  15.     """"""SOME COOL STUFF IN HERE""""""
  16. }
  17.  
  18. Write-Host "Doing something cool now...."
  19. Invoke-ascurrentuser -scriptblock $scriptblock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement