Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

I cannot delete a file using an enviroment variable

$
0
0

Background: I want a script to run for new users and only once so I made a very short cmd the starts a powershell script that creates a shortcut that points to a cmd that deletes 3 folders if there is no flag and then creates a flag and deletes the shortcut that started it.

The powershell script creates a shortcut in:

Powershell
$Shortcut=$WshShell.CreateShortcut("C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\delete firefox profile.lnk")

Then when a new user logs in that becomes a shortcut in:

Powershell
"$Env:AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\delete firefox profile.lnk"

I logged in as a test user and I'm looking at the file as I type but when I try to delete it in cmd or powershell I'm told that the file does not exist.

I can delete it if I reference the explicit...


Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>