Pan1n
Contributor
Contributor

Change output location

Jump to solution

Hi all,

i hope someone can help me, i got this script from internet CPReport and the result is good, but if run the script from tasklist windows, the out put file will be in c:\windows\system32. i want output file on other folder.

If i open the script ther is 2 command that need to change:

$FullPath = ((Get-Location).Path + "\" + $FileName + " $(Get-Date -Format "yyyy-MM-dd").png")

$HTMLPage | Out-File ((Get-Location).Path + "\$vCenterServerName $(Get-Date -Format "yyyy-MM-dd").html")

I try to change

$FullPath = (d:\xxx + "\" + $FileName + " $(Get-Date -Format "yyyy-MM-dd").png")

Error

D:\ReportVMware\Cluster : The term 'D:\ReportVMware\Cluster' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At D:\Drive_D\My Documents\VMware\Script\ReportCluster\KPVCENTER7_V1.ps1:649 char:15
+ $FullPath = (D:\ReportVMware\Cluster + "\" + $FileName + " $(Get- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (D:\ReportVMware\Cluster:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

 

 

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Then you should do

$HTMLPage | Out-File "d:\xx\xx\$vCenterServerName $(Get-Date -Format 'yyyy-MM-dd').html"

or

$path = 'd:\xx\xx'
$HTMLPage | Out-File "$path\$vCenterServerName $(Get-Date -Format 'yyyy-MM-dd').html"


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership

Try like this

$FullPath = "d:\xxx\$($FileName) $(Get-Date -Format 'yyyy-MM-dd').png"


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

0 Kudos
Pan1n
Contributor
Contributor

Thanks LucD it`s working.

but for the HTML page it`s not working.

the command is like this:

$HTMLPage | Out-File ((Get-Location).Path + "\$vCenterServerName $(Get-Date -Format "yyyy-MM-dd").html")

What i already try to change is become : $HTMLPage | Out-File (D:\ReportVMware\Cluster + "$($vCenterServerName) $(Get-Date -Format "yyyy-MM-dd").html")

Error:

D:\ReportVMware\Cluster : The term 'D:\ReportVMware\Cluster' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At D:\Drive_D\My Documents\VMware\Script\ReportCluster\KPVCENTER7_V1.ps1:911 char:23
+ $HTMLPage | Out-File (D:\ReportVMware\Cluster + "$($vCenterServerName ...
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (D:\ReportVMware\Cluster:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

0 Kudos
LucD
Leadership
Leadership

You are making the same mistake again by not using a string.

$HTMLPage | Out-File "$((Get-Location).Path)\$vCenterServerName $(Get-Date -Format 'yyyy-MM-dd').html"


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

0 Kudos
Pan1n
Contributor
Contributor

Hi LucD,

 

Yes i missing the string, but if using your command the HTML file will save in get-location path,but i want to save HTML page on other folder like d:\xx\xx\vcentername 20201216.html.

 

Thanks for your help

0 Kudos
LucD
Leadership
Leadership

Then you should do

$HTMLPage | Out-File "d:\xx\xx\$vCenterServerName $(Get-Date -Format 'yyyy-MM-dd').html"

or

$path = 'd:\xx\xx'
$HTMLPage | Out-File "$path\$vCenterServerName $(Get-Date -Format 'yyyy-MM-dd').html"


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

View solution in original post

0 Kudos
Pan1n
Contributor
Contributor

It`s working..thank you very much 🤝

0 Kudos