1

I used Running a command as Administrator using PowerShell? to self-elevate my powershell script to copy a file and schedule a job on Windows 10 machines:

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"";
    exit;
}

But the copy process:

Copy-Item -Path (c:\example\powershellw.exe') -Destination 'c:\windows\system32\WindowsPowerShell\v1.0'

Works in my local machine but on the remote machines (different privileges) not:

a. It DOES copy the file BUT b. the file is only readable by commandline "dir" and NOT visibile in Windows Explorer and not in task scheduler leading to "file not found" in task scheduler even when run with admin privileges (https://superuser.com/questions/1382965/powershell-cant-see-all-files-in-a-directory)

The file has just A and not different attribs, it has access from system, users, administrator but still its not visible in explorer. When I start a powershell session as admin manually and run this line, the file becomes visible ...

So what is the difference between manually running the line on an elevated powershell prompt versus running the script auto with the self-elevated line ?

edelwater
  • 2,650
  • 8
  • 39
  • 67

0 Answers0