Microsoft Virtualization Discussions

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

tsener

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

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

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

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

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

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 

.

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public