powershell create folder in other userprofile with administrative privilege -


i have user standard right, , need run powershell script admin right something, , finnaly create folder , copy single file in current logged userprofile. how can this?

example:

c:\users\username\foo\foo.txt

i but, obviusly, create folder in admin profile

# somethings before     $directory = $env:userprofile + 'foo'      if(!(test-path -path $directory)){     new-item -path $env:userprofile -name "foo" -itemtype "directory" } copy-item "testo.txt" -destination $directory   # copy-item "ardigicore.ini" -destination $ardigisign 

thanks in advance

edit:

1 - run powershell script, logged standard user (e.g. user1), admin (e.g. admin1).

2 - script install program, , before end, check , in case create folder in path c:\users\users1\foo

nb: not know before name of user logged in execute program

you can use query.exe pull current users. filter active user isn't you.

$user = (((& query user) | ? {$_ -like "*active*" -and $_ -notlike "adminusername"}).trim()  -replace '\s+',' ' -split '\s')[0] #credit jaap brasser https://gallery.technet.microsoft.com/scriptcenter/get-loggedonuser-gathers-7cbe93ea 

then convert sid , match sid returned win32_userprofile

$ntuser = new-object system.security.principal.ntaccount($user) $sid = ($ntuser.translate([system.security.principal.securityidentifier])).value $directory = (gcim win32_userprofile | ? {$_.sid -eq $sid}).localpath  if(!(test-path -path (join-path $directory foo))){     new-item -path $directory -name "foo" -itemtype "directory" } copy-item "testo.txt" -destination (join-path $directory foo) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -