Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Friday, August 5, 2016 1:03 PM
Hi, created a powershell script to copy some backup files from a remote server to a share on another centralized server.
When trying to run a simple get-childitem on the remote server:
Get-ChildItem \server\d$\DbBackup'
I am getting the error:
Message
Executed as user: domain\_Agt. The job script encountered the following errors. These errors did not stop the script: A job step received an error at line 3 in a PowerShell script. The corresponding line is 'gci '\server\d$\DbBackup'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot find path ''\server\d$\DbBackup' ' because it does not exist. '. Process Exit Code 0. The step succeeded.
So is this because the I am not using a normal shared folder? It works when I try to do the same command on a shared folder.
Anyway the script works in "normal" powershell, but not in the SQL powershell I run from the agent job.
Friday, August 5, 2016 1:11 PM ✅Answered
Get-ChildItem \server\d$\DbBackup'
Hello,
D$ is a dedicated admin share where only admins or user with elevated permissions can access it; I don't think your SQL Server-Agent Service account do have These permissions
Olaf Helper
Friday, August 5, 2016 5:31 PM ✅Answered
Only local administrators can see {driveletter}$ shares. It doesn't matter what rights they granted.
You need to create another share, you can use $ if you want it to be hidden from the list, but you cannot use the built in shares unless you are local administrator.
Sunday, August 7, 2016 1:14 PM ✅Answered
Starta by not using an admin share. I.e., create a "proper" share. Grant access to Agent's service account (need to be a domain account) to that share. Read this http://sqlblog.com/blogs/tibor_karaszi/archive/2009/09/19/sql-server-agent-jobs-and-user-contexts.aspx. Then post back if you need more help. :-)
Tibor Karaszi, SQL Server MVP (Web Blog)
Friday, August 5, 2016 1:21 PM
I have actually granted the access rights.. and if it was about permissions I thing the message would say that.. (?)
Friday, August 5, 2016 2:17 PM
Have you tried setting your location in the script to a normal drive folder first? If this is run in a normal Powershell job step, the module may be setting your location to the SQLServer:\ virtual drive in which case UNC paths like the one you are attempting won't work.
Try something like Set-Location c:\ before you attempt to access the UNC path and see if that clears it up.
If it does you can simulate the problem by running Import-Module SQLPS in Powershell ISE and see that working directory is automatically switched to SQLServer:\ and that if you attempt something like a Get-ChildItem on a UNC path that it will fail with the same error.