August 6, 2015 at 11:05 am
I am new to Powershell and I am not sure what to do in regards to the following issue that I am experiencing.
I have the following script that I use to copy the SQL BAK files from my server to my NAS. I consider this a safety measure to make sure that I have a copy of the SQL BAK file outside of my server. The way this script works is very simple. Simply create a SQL job and make sure that "Type:Powershell" is selected, schedule the job and presto change-o! Your BAK files will be copied remotely to your NAS. This script works perfectly fine with Windows 2008 R2 however it does not on Windows 2012.
When I run the SQL job on a Windows 2012 R2 server the job reports that it ran successfully. However when I check the NAS folder no files are copied. I check the logs and the logs reports that the job ran successfully as well.
param
(
[Parameter(Position=0, Mandatory=$true)] [string]$SrcFolder,
[Parameter(Position=1, Mandatory=$true)] [string]$TgtFolder
)
##copy
robocopy $SrcFolder i:\sqlbackups $TgtFolder \as2\sqlbackups\SERVERNAME /e /copy:dat /log+:i:aslog\log.txt
##set exit code
$exit = $lastexitcode -band 24
exit $exit
So I proceeded to put on my troubleshooting hat to determine why this script was failing to copy the files. I first checked to see if I could run the robocopy cmd without the powershell syntax. So I opened a command (admin) shell and I ran the following command like so.
robocopy i:\sqlbackups \as2\sqlbackups\SERVERNAME /e /copy:dat
As I expected to see this command ran just fine with no issues. 🙂
So I then proceeded to the next step and copied the powershell script to my windows powershell ISE. I ran the script and it prompted me with the following.
cmdlet at command pipeline position 1
Supply values for the following parameters:
SrcFolder:
I never seen this before and I suspect it has something to do with Windows 2012 R2. I want this script to run without any prompting as it does in Windows 2008 R2. Would anyone know how I can resolve this? :unsure:
August 7, 2015 at 1:22 am
ray santalis-466762 (8/6/2015)
\as2\sqlbackups\SERVERNAME
This is not a properly formed UNC path
its been discussed recently on this forum but I can't see the point of using robocopy and wrapping it in a PoSh script.
Build a collection of files and invoke the PoSh "copy-item' cmdlet, works perfectly.
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply