cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
924
Views
0
Helpful
1
Replies

PowerShell script issue

jimstehlik
Level 1
Level 1

Hello All,

I am creating a script to backup all of my UCS domains in one pass.  I have created the proper credential file so that is not the issue.  The issue happens when trying to create the output filename to include the domain name as part of the file name.  For whatever reason, I can't get it to replace the variable with the domain name.  Here is the snippet of code, where I am just using echo to verify the file names to be created:

Import-Module CiscoUcsPS

$a = Set-UcsPowerToolConfiguration -SupportMultipleDefaultUcs $true

$CredFileKey = ConvertTo-SecureString 'timetolockit' -AsPlainText -Force

$hanele1 = connect-ucs -LiteralPath C:\scripts\creds\all.xml -key $credfilekey

$date = Get-Date -format "MM-dd-yyyy"

$fname = "C:\backup\" + ${ucs} + "-" + $date + "-full-state.xml"

echo $fname

Thank you,

Jim

1 Accepted Solution

Accepted Solutions

ericwill
Cisco Employee
Cisco Employee

Jim:

You are very close.  What you don't need to do is do the variable's for date / time / etc like you are doing.  The backup-ucs cmdlet will do that for you using the -PathPattern flag like this:

Import-Module CiscoUcsPS

$a = Set-UcsPowerToolConfiguration -SupportMultipleDefaultUcs $true

$CredFileKey = ConvertTo-SecureString 'timetolockit' -AsPlainText -Force

$handle1 = connect-ucs -LiteralPath C:\scripts\creds\all.xml -key $credfilekey

$configallbackup = Backup-Ucs -Type config-all -PathPattern 'c:\ucs\backups\${ucs}-${MM}-${dd}-${yyyy}-config-all.xml'

$fullstatebackup = Backup-Ucs -Type full-state -PathPattern 'c:\ucs\backups\${ucs}-${MM}-${dd}-${yyyy}-full-state.bin'

Let me know if that helps.

Eric    

View solution in original post

1 Reply 1

ericwill
Cisco Employee
Cisco Employee

Jim:

You are very close.  What you don't need to do is do the variable's for date / time / etc like you are doing.  The backup-ucs cmdlet will do that for you using the -PathPattern flag like this:

Import-Module CiscoUcsPS

$a = Set-UcsPowerToolConfiguration -SupportMultipleDefaultUcs $true

$CredFileKey = ConvertTo-SecureString 'timetolockit' -AsPlainText -Force

$handle1 = connect-ucs -LiteralPath C:\scripts\creds\all.xml -key $credfilekey

$configallbackup = Backup-Ucs -Type config-all -PathPattern 'c:\ucs\backups\${ucs}-${MM}-${dd}-${yyyy}-config-all.xml'

$fullstatebackup = Backup-Ucs -Type full-state -PathPattern 'c:\ucs\backups\${ucs}-${MM}-${dd}-${yyyy}-full-state.bin'

Let me know if that helps.

Eric    

Review Cisco Networking for a $25 gift card

Review Cisco Networking for a $25 gift card