VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to get the file name

Hi,

Please help to get the filename using variable as I am unable to get.

Please help

$fold = test

$date = Get-Date -format dd-MMM-yyyy-hh-mm-tt

$reportlocation = "D:\reports\("POC_" + "$fold" + "_VM_Reporting_$date").xlsx

I am getting the below error

+ $reportlocation = "D:\reports\("POC_" + "$fold" + "_VM_Reporting_$date").xlsx

+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Unexpected token 'POC_" + "$fold" + "_VM_Reporting_$date").xlsx

#$fold = "Client' in expression or statement.

At D:\Jenkins\Scripts\test.ps1:180 char:67

+                                                                   ~~~~~~~~~~~~~~

The string is missing the terminator: ".

    + CategoryInfo          : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : UnexpectedToken

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

No need to concatenate string swith the + here, just use variable substitution.

$fold = 'test'

$date = Get-Date -Format 'dd-MMM-yyyy-hh-mm-tt'


$reportlocation = "D:\reports\POC_$($fold)_VM_Reporting_$($date).xlsx"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

No need to concatenate string swith the + here, just use variable substitution.

$fold = 'test'

$date = Get-Date -Format 'dd-MMM-yyyy-hh-mm-tt'


$reportlocation = "D:\reports\POC_$($fold)_VM_Reporting_$($date).xlsx"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

You are the champ, Thank you very much Smiley Happy

0 Kudos