Microsoft Virtualization Discussions

How can I write the "Get-NaSnapshotSchedule" full output into the one excel's cell ?

tsener
5,250 Views

Hi all ,

 

a part of my script is as at the below ;

 

I want to write the "Get-NaSnapshotSchedule" full output into the one excel's cell

 

How can I do it ?

 

 

PS > $a1= Get-NaSnapshotSchedule vol0

 

PS > $a1

Volume                          Weeks   Days    Hours  Minutes WhichHours                WhichMinutes             
------                          -----   ----    -----  ------- ----------                ------------             
vol0                              0       2       6       0    8,12,16,20              

 

 

$a2= $a1.Weeks , $a1.Days , $a1.Hours , $a1.Minutes , $a1.WhichHours , $a1.WhichMinutes

 

$ws3.Cells.Item(1,1) =  $a2[0] , $a2[1] , $a2[2] , $a2[3] , $a2[4] , $a2[5]

 

 

output is ; only $a2[0] (is equal to "0")

 

 

 

5 REPLIES 5

JGPSHNTAP
5,240 Views

Why are you trying to use the excel api.  That's not necassary in this case

 

 

use this

 

get-nasnapshot vol | epcsv c:\filername.csv -notypeinformation

 

 

tsener
5,226 Views

Hi JGPSHNTAP ,

 

 

the output is different "get-nasnapshot vol | epcsv c:\filername.csv -notypeinformation"

 

I need "Get-NaSnapshotSchedule output into the one excel's cell.

 

 

I have tried "Get-NaSnapshotSchedule vol0 | epcsv d:\filername1.csv -notypeinformation" but it is not working good for me .

 

 

 

 

 

 

 

 

 

Shashanka
5,186 Views

You can try using PSCustomObject to achieve this.

 

create a custom object 

 

 

 

$custobj = [pscustomobject]@{cellname=$a1.weeks + $a1.days + $a1.hours + $a1.minutes}      

                                               #here cellname is the Excel Cell name , where you want to put the entire stuff

$custobj | Export-Csv filename.csv

 

 

Note:

This is just an idea to do, please tweak it according to your needs.

 

Regards,

Shashank

tsener
5,134 Views

Hi Shashanka ,

 

I tried your recommendation as at the below ,

 

$ad = get-nasnapshotschedule $Vol[0].name

 

PS > $ad

Volume                          Weeks   Days    Hours  Minutes WhichHours                WhichMinutes             
------                          -----   ----    -----  ------- ----------                ------------             
vol0                              0       2       6       0    8,12,16,20                              

 

 

$custobj = [pscustomobject]@{ad2=$ad.weeks + $ad.days + $ad.hours + $ad.minutes}

 

PS > $custobj

ad2
---
  8

 

 

I need that output in a one cell ;

 

0       2       6       0    8,12,16,20

 

or

 

week:0 days:2 hours:6 minutes:0 WhichHours:8,12,16,20

 

 

 

ad2: cell name.

FelipeMafra
5,042 Views

Hello,

 

I think you are looking for this:

 

$var = "{0} {1} {2} {3}" -f $a.Weeks, $a.Days, $a.Hours, $a.Minutes

The problem with $a.Weeks + $a.Days is because both are numbers. Powershell will try the add operation on numbers which is 6 + 2 = 8. You have to force them to be a string if you want to concatenate them.

 

$var.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                  
-------- -------- ----                                     --------                                                                                                                  
True     True     String                                   System.Object 

.

Public