我们最近在 Windows Server 2012(从 Windows Server 2008 R2)上升级到 SQL Server 2012(从 SQL Server 2008 R2),并且之前运行没有错误的 SQL Server 作业代理作业现在失败了。
该作业有一个 Powershell 作业步骤:
$ErrorActionPreference = 'Stop'
$DateStamp = Get-Date -format "yyyyMMdd"
$BizUnit = 'SHB'
# Target File directory
$BaseDir = '\\MyFileServer\MyDirectory'
$Query = "EXEC dbo.usp_MyQuery '$BizUnit'"
$TargetFile = "MyTargetFile_" + $BizUnit + "_$DateStamp.xml"
$TargetDir = (Join-Path -Path $BaseDir -ChildPath $BizUnit)
$Query | Out-File -FilePath (Join-Path -Path $TargetDir -ChildPath $TargetFile) -Force -Encoding "utf8"
Run Code Online (Sandbox Code Playgroud)
当作业运行时,它失败并显示以下错误消息:
作业步骤在 PowerShell 脚本的第 14 行收到错误。对应的行是 '$Query | Out-File -FilePath …
我有一个备份 SSAS 数据库的程序。
这是一种魅力。
现在我的服务器被 SSAS 备份填满,我想删除超过 2 天的备份文件。
为了实现这一点,我使用了以下 POWERSHELL 脚本:
#-------------------------------------------------------------------------------
# Script to delete old SSAS backup files
#
# Marcelo Miorelli
#
# 19-novembre-2014 Wed
#-------------------------------------------------------------------------------
#-- connect to the remote server -- SQLBILON1
#
ENTER-PSSESSION sqlbilon1
#-- set the Path where the backup files (.abf) are located
#
$path = 'H:\SQLBackups'
#-- set the number of days backups should be deleted -- in this case 2
#
$NumberOfDays = 2
#-- …
Run Code Online (Sandbox Code Playgroud)