简体   繁体   English

Powershell脚本在Windows 2008 R2上运行良好,但在Windows 2012 R2上不执行任何操作

[英]Powershell script runs fine on Windows 2008 R2 but does nothing on Windows 2012 R2

I am new to Powershell and I am not sure what to do in regards to the following issue that I am experiencing. 我是Powershell的新手,我不确定该如何处理我遇到的以下问题。

I have the following script that I use to copy the SQL BAK files from my server to my NAS. 我使用以下脚本将SQL BAK文件从服务器复制到NAS。 I consider this a safety measure to make sure that I have a copy of the SQL BAK file outside of my server. 我认为这是一项安全措施,以确保我在服务器外部具有SQL BAK文件的副本。 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! 只需创建一个SQL作业,并确保选择“ Type:Powershell”,安排该作业并保存更改-o! Your BAK files will be copied remotely to your NAS. 您的BAK文件将被远程复制到NAS。 This script works perfectly fine with Windows 2008 R2 however it does not on Windows 2012. 该脚本可以在Windows 2008 R2上正常运行,但不能在Windows 2012上运行。

When I run the SQL job on a Windows 2012 R2 server the job reports that it ran successfully. 当我在Windows 2012 R2服务器上运行SQL作业时,该作业报告其运行成功。 However when I check the NAS folder no files are copied. 但是,当我检查NAS文件夹时,没有文件被复制。 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. 我首先检查一下是否可以在没有Powershell语法的情况下运行robocopy cmd。 So I opened a command (admin) shell and I ran the following command like so. 因此,我打开了一个命令(admin)shell,然后像这样运行了以下命令。

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. 因此,我继续下一步,将powershell脚本复制到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: 命令管道位置1上的cmdlet为以下参数提供值:SrcFolder:

I never seen this before and I suspect it has something to do with Windows 2012 R2. 我以前从未见过这种情况,我怀疑它与Windows 2012 R2有关。 I want this script to run without any prompting as it does in Windows 2008 R2. 我希望该脚本能够像Windows 2008 R2一样运行而没有任何提示。 Would anyone know how I can resolve this? 谁知道我该如何解决?

The reason it prompts in ISE is because you have mandatory parameters that you aren't supplying. 它在ISE中提示的原因是因为您具有不提供的强制性参数。 It would do the same thing on 2008 R2 / PowerShell 2.0. 它将在2008 R2 / PowerShell 2.0上执行相同的操作。

I don't think this has to do with why it's not working on 2012 R2 though. 我认为这与为什么在2012 R2上无法正常运行无关。 It sounds like you're trying to run this directly from SQL server, so I have to assume that the 2 different operating systems indicates that you have 2 different instances of SQL server running. 听起来您正在尝试直接从SQL Server运行此操作,因此我必须假定2个不同的操作系统指示您有2个不同的SQL Server实例正在运行。

From that, I suspect that the job is being run as 2 different users, and one of them has access to the NAS and the other doesn't. 因此,我怀疑该作业是以2个不同的用户身份运行的,其中一个用户可以访问NAS,而另一个用户没有访问权限。

Some speculation here, but I will update the answer if you have more details. 这里有些猜测,但是如果您有更多详细信息,我将更新答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 绕过Windows Server 2008 R2 UAC并以管理员身份运行脚本 - Bypass Windows Server 2008 R2 UAC and run a script as Administrator Windows Server 2008 R2上的连接超时= 0 - Connection Timeout=0 on Windows Server 2008 R2 SQL 查询 XML 在 2000 年运行良好,在 2008 年 R2 运行缓慢 - SQL Query FOR XML runs fine in 2000, slow in 2008 R2 在Windows Server 2008 R2上安装SQL Server 2012时,需要哪些Windows服务器角色(如果有)? - When installing SQL Server 2012 on Windows Server 2008 R2 what Windows Server Roles, if any, are required? 将 SQL Server 2008 R2 升级到 2012 - Upgrade SQL Server 2008 R2 to 2012 Windows Server 2012 R2 + XAMPP + SqlSrv =迄今未成功 - Windows Server 2012 r2 + XAMPP + SqlSrv = unsuccessful so far Windows Server 2012 R2上的MSSQL Server远程登录问题 - MSSQL Server Remote Login Issue on Windows Server 2012 R2 在Tomcat 7.0上运行网站:Windows 2008 R2 - Running website on Tomcat 7.0: Windows 2008 R2 SQL Server 2008 R2禁用Windows身份验证登录 - SQL Server 2008 R2 disable login from Windows Authentication Windows 10上无法访问本地SQL Server 2008 R2数据库 - Local SQL Server 2008 R2 database not accessible on Windows 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM