none
$env:USERPROFILE\AppData acces denied RRS feed

  • Question

  • Hi there,

    I'm trying to automate copying .htm email signatures to the appdata folder of users using powershell.

    My script so far:

    $first = Read-Host "Enter your Firstname here"
    $sur = Read-Host "Now type your Surname"
    $A = Get-Content Email_sign.htm
    $A | ForEach-Object {$_ -Replace "Firstname", "$first" -Replace "Surname", "$Sur"} | Set-Content Email_sign.htm -Force

    $outlook = Read-Host "Do you use Outlook (y/n)?"
    if ($outlook -eq "j") {copy EmailHandtekening_tijdelijk.htm $env:USERPROFILE\AppData\Roaming\Microsoft\Signatures\Email_sign.htm}

    now i get the error "+ CategoryInfo          : PermissionDenied: (C:\Users\wim.du...Email_sign.htm:FileInfo) [Copy-Item], UnauthorizedAccessException

    We don't want to add admin credentials because the script wil be copied to the devices of all our employees.
    Can anyone help me with a workaround?

    Greetings Wim

    Thursday, March 30, 2017 8:02 AM

Answers

  • I've found the solution in robocopy: 

    $first = Read-Host "Enter your Firstname here"
    $sur = Read-Host "Now type your Surname"
    $A = Get-Content Email_sign.htm
    $A | ForEach-Object {$_ -Replace "Firstname", "$first" -Replace "Surname", "$Sur"} | Set-Content Email_sign.htm -Force

    $outlook = Read-Host "Do you use Outlook (y/n)?"
    if ($outlook -eq "j") {robocopy "$env:USERPROFILE\Documents\email\" "$env:USERPROFILE\AppData\Roaming\Microsoft\Signatures\" Email_sign.htm}

    else {exit}

    • Marked as answer by Wim Duizer Thursday, March 30, 2017 11:35 AM
    Thursday, March 30, 2017 11:35 AM

All replies

  • By default user folders are protected.  Group ,policy can override this.  Post in GP forum to learn how to do this.

    \_(ツ)_/

    Thursday, March 30, 2017 9:00 AM
  • I've found the solution in robocopy: 

    $first = Read-Host "Enter your Firstname here"
    $sur = Read-Host "Now type your Surname"
    $A = Get-Content Email_sign.htm
    $A | ForEach-Object {$_ -Replace "Firstname", "$first" -Replace "Surname", "$Sur"} | Set-Content Email_sign.htm -Force

    $outlook = Read-Host "Do you use Outlook (y/n)?"
    if ($outlook -eq "j") {robocopy "$env:USERPROFILE\Documents\email\" "$env:USERPROFILE\AppData\Roaming\Microsoft\Signatures\" Email_sign.htm}

    else {exit}

    • Marked as answer by Wim Duizer Thursday, March 30, 2017 11:35 AM
    Thursday, March 30, 2017 11:35 AM