I'm running a script in an SSIS package and I specify an account to run the package in SQL Server Agent. When it runs, I am unable to get the value of $ENV:LOCALAPPDATA
Here's my code along with writing out the LOCALAPPDATA value
Start-Transcript
-Path
"\\........\log-test.txt"
Write-Output "Local App Data: "
Write-Output $ENV:LOCALAPPDATA
#Trust the repository used to prevent required user input
Set-PSRepository
-Name
"PSGallery"
-InstallationPolicy
Trusted
However, the log file outputs this and errors out when trying to use $ENV:LOCALAPPDATA to build a path for another variable using Join-Path because the value is blank.
Transcript started, output file is \xxxxxxxxxxxxxxxxx\log-test.txt
Local App Data:
PS>TerminatingError(Join-Path): "Cannot bind argument to parameter 'Path' because it is null."
If I log in as the user that the job is running as and then let the job run as scheduled, it works fine. Why is this field blank unless I'm physically logged onto the server as that user?