0

Good evening everyone,

Im trying to remove some stuff and it must be in a separate powershell window. The problem is than i cannot pass the path variable to that powershell Window, it should be something like this:

$path = "\\server01\test path"
Start-Process powershell -WindowStyle Normal {
      Remove-Item -path "$path\file.txt" -Recurse -Force
}-Verb runas

any recommendations?

3
  • 3
    Why -Recurse if you only want to remove file.txt ? Please explain what you need to remove, why it must be in a separate powershell window and also show us what your code does now (and what it should do). Edit your question and put that info in there Commented Apr 12 at 9:36
  • Even env: vars won't work with runas, unless you want to do a param start-process powershell '& { param($b); echo $b;pause } "there"' -verb runas Commented Apr 12 at 15:17
  • In short: Best to avoid passing a script block to Start-Process' (here positionally implied) -ArgumentList parameter. If you do, it is invariably stringified, which results in its verbatim content (sans { and }) being passed, thereby preventing the use of variable values from the caller's scope. In order to incorporate the latter, you must pass the code as an expandable string ("...") instead, with embedded double-quoting around variable references as necessary. See the linked duplicate for details. Commented Apr 12 at 16:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.