Powershell script for Cisco Security Manager scheduled report

With permission from my friend Kyaw Zin I can post the script here for people who use Cisco Security Manager 4.3. The Cisco Security Manager – Report Manager can do schedule report generation, however the report is saved with schedule name, each time a report generated it overwrites the previous report due to same name, customer will definitely want to archive the generated report hence my friend had found a solution through powershell script to append the date and and time to the generated report name.

Param(
    [string]$from,
    [string]$to
)

function copy_file($file, $no)
{
    $now = [datetime]::now.ToString('_dd-MM-yy_HHmmss')
    $dest = $file.BaseName+ $now
    
    if($no -gt 0)
    {
        $dest = "$($dest) $now"
    }

    if(Test-Path "$to\$dest$($file.Extension)")
    {
        copy_file $file ($no + 1)
    }

    Copy-Item $_ -Destination "$to\$dest$($file.Extension)" -Force
}

ls $from\*.* | % {
    Write-Host "Copying $_" -ForegroundColor Yellow
    copy_file $_ 0 
}

To apply the script open power shell and type backup-ps1 -from "c:\path\of_the_report" -to "c:\destination\folder_of_the_report"

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s