I have a procedure to backup SSAS Databases.
That is working as a charm.
Now my server is filling up with SSAS backups and I would like to delete the backup files that are older than 2 days.
to achieve this I am using the following POWERSHELL script:
#-------------------------------------------------------------------------------
# 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
#-- calculate the date of the backup files - if they are older than $days they will be deleted
#
$days = (Get-Date).AddDays(-$NumberOfDays)
#--get the list of the backup files to be deleted and delete them
#
Get-ChildItem $Path -Recurse '*.abf' | ? {$_.CreationTime -lt $days} | Remove-Item
The problem with this script is that I use MYSQLSERVER1 server to backup the databases that are on SQLBILON1 server. The backup files are on the folder H:\SQLBackups of SQLBILON1.
The job is failing with the following error message:
The job script encountered the following errors. These errors did not stop the script:
A job step received an error at line 13 in a PowerShell script.
The corresponding line is 'ENTER-PSSESSION sqlbilon1'.
Correct the script and reschedule the job. The error information returned by PowerShell is:
'Connecting to remote server failed with the following error message :
Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.'
Question, how can I run a PowerShell script on a remote server? This script runs from a sql server job.
Can I create a proxy and use it to connect to the remote server?