0

In powershell i can download a script in a specific random name created folder but i cannot find the right way to execute the script from there.Here the code that i used:

$uuid=(Get-WmiObject Win32_ComputerSystemProduct).UUID;
$path = $env:appdata+'\'+$uuid; $h=$path+'\d';  
if(!(test-path $path)) { New-Item -ItemType Directory -Force -Path 
$path;};
Invoke-WebRequest mywebsitefordownloadingscript -OutFile $path\\test.txt;
start-process -Windowstyle hidden cmd '/C 
'powershell.exe' -exec bypass $path\\test.txt';

there was something missing in last string maybe the problem persist if i use '+$path+' too.

Any suggestions??

0

1 Answer 1

3

The problem is your single quotes on the last two lines. Since you have enclosed $path within single quotes it is not expanded and is taken literally. Change to double quotes to expand the variable, and this should work.

$uuid=(Get-WmiObject Win32_ComputerSystemProduct).UUID
$path = $env:appdata+'\'+$uuid
$h=$path+'\d'
if(!(test-path $path)) { 
    New-Item -ItemType Directory -Force -Path $path
}
Invoke-WebRequest mywebsitefordownloadingscript -OutFile $path\\test.txt
start-process -Windowstyle hidden cmd "/C 'powershell.exe' -exec bypass $path\\test.txt"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.