Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Powershell for network path

$
0
0
I am totally new to powershell(just 2 days) so please bear my ignorance.Here is the code I am trying to execute as a sql agent job that basically deletes files over 2 days old.[code]function LoopFolders([string]$path,[string]$logpath) { $fs = new-object -com scripting.filesystemobject $folder = $fs.getfolder($path) $today = get-date -uformat "%Y_%m_%d" $log = $logpath + "Deleted_" + $today + ".log" foreach ($i in $folder.files) { if($folder.path -contains "Master" -or $folder.path -contains "Model" -or $folder.path -contains "Certificates") {break} else { $dt = ((Get-Date) - $i.DateLastModified).Days if ($dt -gt 2 -and $i.PsISContainer -ne $True ) { $deleted = "Deleting - " + $i.path + " - Last Write Time - " + $i.DateLastModified add-content $log -value $deleted remove-item $i.path } } } foreach ($i in $folder.subfolders) { LoopFolders($i.path) }}LoopFolders "C:\DatabaseBackUps" "C:\DatabaseBackUps\BackUpDeleteLogs"LoopFolders "\\10.1.1.10\DatabaseBackups" "\\10.1.1.10\Database\BackUpDeleteLogs"[/code]The problem here is that the code works fine for local path but errors out for network path with the following message.[code="plain"]The corresponding line is 'remove-item $i.path'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Invalid Path: '\\10.1.1.10\database\LogBackUp\PRODUCTION_ALLIED\PRODUCTION_ALLIED_backup_2012_06_01_093000_6722391.trn'. '. Process Exit Code -1. The step failed.[/code]The same question has been asked herehttp://social.technet.microsoft.com/Forums/da-DK/winserverpowershell/thread/a1a1ba21-0bd5-4b53-8838-5930f9599024

Viewing all articles
Browse latest Browse all 467

Trending Articles