User and System Deployment Settings

Hello there everyone, know that I have discovered my issue I wanted to ask for some guidelines/help on how this package can work out.

I have put together a toolkit package that does the following:

Pre-Installation Step:

If (Test-Path “$envAppData\xxx\xxx\xx\xxx\xxx\xxx.XML”) {
Remove-Item -Path “$envAppData\xxx\xxx\xx\xxx\xxx\xxx.XML” -Force
Write-Log -Message “xxx.XML Deleted” -Source “DeleteFile” -Severity “2”
}
Else {
Write-Log -Message “xxx.XML Delete Failed” -Source “RenameFile” -Severity “3”
}

Installation Step:

If (Test-Path “$envProgramFilesX86\xxx\xxx”) {
Copy-Item -Path “$dirFiles\xxx.XML” -Destination “$envProgramFilesX86\xxx\xxx” -Force
Write-Log -Message “Copied xxx XML” -Source “CopyFile” -Severity “2”
}
Else {
Write-Log -Message “Copied xxx XML Failed” -Source “ProgramFiles” -Severity “3”
}

In SCCM: I am choosing “Install For System”
PS Toolkit Config: Admin Rights Required

As you can see I am trying to make changes to two separate environments and of course it not working. How can I make this work together?

Thank you for your time and help with this issue, appreciate the help :slight_smile:

$envAppData under user SYSTEM does not point to where you would want it to since its not running under the user you want. You can either go through every user on the machine or find out who is currently logged in and use their username to form the path.

Thank you for the feedback. I have been thinking about this also and thought about calling a separate script in the PS Toolkit that takes care of the user part and finished the System part. Is it possible to get an example of what you are sharing with me?

# Check who is the currently logged in user
If ($RunAsActiveUser -and ($RunAsActiveUser.UserName -ne "SYSTEM") {
    # Prepare the path
    $RemovalPath = "$envSystemDrive\Users\$($RunAsActiveUser.UserName)\AppData\Local\xxx\xxx.xml"
    # Test and remove the file
    If (Test-Path $RemovalPath -PathType Leaf) {
        Remove-Item -Path $RemovalPath -Force
        Write-Log -Message "xxx.XML Deleted" -Source "DeleteFile" -Severity 2
    } else {
        Write-Log -Message "xxx.XML Delete Failed - Not found" -Source "DeleteFile" -Severity 3
    }
} else {
    Write-Log -Message "xxx.XML Delete Failed - No valid user found" -Source "DeleteFile" -Severity 3
}
2 Likes

You can also use this one if you want to delete the files with onestep from all user accounts on the machine:

    $ProfilePaths = Get-UserProfiles | Select-Object -ExpandProperty 'ProfilePath' 
    foreach ($Profile in $ProfilePaths ){
         ### Want you want to do ###
    }
1 Like