Powershell logon script remove item

I have a logon script that does the following:

$user = $env:username
remove-item -path c:\users\$user\appdata\local\FOLDER -recurse

It gets the username and removes a specific folder in the appdata of the user.

If I run this in the session of the user (without elevated rights) using powershell , it works. However, if I run it via login script, it doesn't work. The script itself runs since other code ran correctly.

What am i doing wrong?

1 answer

  • answered 2019-02-05 10:44 Mudit Bahedia

    Try -Force switch if it helps.

    $user = $env:username
    remove-item -path c:\users\$user\appdata\local\FOLDER -recurse -Force