VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

use of date command_powercli

Hi Luc ,

can you please check the following .i want to utilize $date in out-file command so that name of the output file has date componenet in it,

can you please suggest what is the right way of doing it.

$path='C:\Users\user1\Desktop\scriptfolder'

$date=get-date

get-cluster|out-file -filepath $path\$date.txt

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

When you use double quotes, you can use variable/expression substitution in a string.

Something like this for example

$path = "C:\Users\user1\Desktop\scriptfolder\report-$(Get-Date -Format 'yyyyMMdd-HHmm').txt"

Get-Cluster| Out-File -FilePath $path


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

When you use double quotes, you can use variable/expression substitution in a string.

Something like this for example

$path = "C:\Users\user1\Desktop\scriptfolder\report-$(Get-Date -Format 'yyyyMMdd-HHmm').txt"

Get-Cluster| Out-File -FilePath $path


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks.

0 Kudos