Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
So, i'm just starting to play with powershell, so bare with the basic questions....
I want to know what the difference between
get-navol | get-nasnapshot -snapname "{*"
and
get-navol | get-nasnapshot -snapname "{*" | Select Name,Created,Total,CumulativeTotal | format-table -autosize
The first one gives me more of a friendly view, but all i did is pipe get-nasnapshot to get-member to review the properties and I was just trying to reproduce what the first query has, but the second query gives me results like.
Name | Created | Total CumulativeTotal |
---- | ------- | ----- --------------- |
{4b74d573-74bf-4475-818e-42ab85ef2b4d} 3/10/2012 11:33:46 AM 4177997824 | 14790995968 |
Instead of something like
Name | Created | Total Cumulative Dependency | |
---- | ------- | ----- ---------- ---------- | |
{4b74d573-74bf-4475-818e-42ab85ef2b4d} | 3/10/2012 | 3.9 GB | 13.8 GB |
Also, what i'm looking to do is loop this through a list of filers and have it list volume name first and then snapshot info.. I was having an issue with that query.
Any assistance is appreciated.
The PowerShell Toolkit includes data formatters, which provide the tabular output with neatly formatted values for the most common output types. When you pipe the output to Select-Object and Format-Table, you're bypassing the built-in formatters so you get the raw underlying data instead and it's up to you to format the data however you like.
Ah.. Ok, sweet.. That explains that.. Now time to get the query...
Ok, here's my little script
gc $hostFile |% {
$nacontroller = Connect-NaController $_ -Credential $cred -Transient:$true
Get-NaVol -Controller $natcontroller | get-nasnapshot -snapname "{*"
}
What's the proper way to get the volume name along with snapshot name.
Try something like this to replicate what the built-in formatters are doing:
PS C:\> Get-NaVol vol* | Get-NaSnapshot -SnapName nightly.* | select TargetName,Name,Created,Total,CumulativeTotal,Dependency | ft @{Expression={$_.TargetName};Label="Volume";Width=20},@{Expression={$_.Name};Label="Name";Width=25},@{Expression={$_.Created.ToShortDateString()};Label="Created";Width=12},@{Expression={ConvertTo-FormattedNumber $_.Total DataSize "0.0"};Label="Total";Width=10},@{Expression={ConvertTo-FormattedNumber $_.CumulativeTotal DataSize "0.0"};Label="Cumulative";Width=10},@{Expression={$_.Dependency};Label="Dependency"}
Volume Name Created Total Cumulative Dependency
------ ---- ------- ----- ---------- ----------
vol0 nightly.0 3/14/2012 20.6 MB 31.4 MB
vol0 nightly.1 3/13/2012 21.5 MB 75.3 MB
vol0 nightly.2 3/11/2012 20.4 MB 166.3 MB
vol1 nightly.0 3/14/2012 88.0 KB 172.0 KB
vol1 nightly.1 3/13/2012 88.0 KB 348.0 KB
vol1 nightly.2 3/11/2012 88.0 KB 704.0 KB
vol1clone nightly.0 3/14/2012 112.0 KB 200.0 KB
vol1clone nightly.1 3/13/2012 104.0 KB 408.0 KB
vol1clone nightly.2 3/11/2012 88.0 KB 800.0 KB
vol3 nightly.0 3/14/2012 52.0 KB 108.0 KB
vol3 nightly.1 3/13/2012 60.0 KB 228.0 KB
vol3 nightly.2 3/11/2012 60.0 KB 460.0 KB
Clinton,
Ok, i like the output and what you did for the built in formatters. I had to adjust column width based on lenght of name of vol and snap.
[Quote}
gc $hostFile |% {
$nacontroller = Connect-NaController $_ -Credential $cred -Transient:$true
Get-NaVol | Get-NaSnapshot -SnapName "{*" | select TargetName,Name,Created,Total,CumulativeTotal | ft @{Expression={$_.TargetName};Label="Volume";Width=40},@{Expression={$_.Name};Label="Name";Width=40},@{Expression={$_.Created.ToShortDateString()};Label="Created";Width=12},@{Expression={ConvertTo-FormattedNumber $_.Total DataSize "0.0"};Label="Total";Width=10},@{Expression={ConvertTo-FormattedNumber $_.CumulativeTotal DataSize "0.0"};Label="Cumulative";Width=10}
}
[/quote]
So I have some questions. Why on earth is the loop not going through the file. It keeps hitting the first controller in the file. Its driving me nuts..
Also, based on your expression statement, when you are adjusting the size you use DateSize "0.0". What is that actually doing behind the scenes? Im curious?
Thanks
Josh, you are passing -Transient to Connect-NaController, which causes that cmdlet to not store the connection context in the session variable $global:CurrentNaController. If you do that, then you must pass the controller context to each subsequent cmdlet. It's simpler to use the global variable, like this:
PS C:\> gc controllers.txt | % { $c = Connect-NaController $_; Write-Host "`nController: $c`n"; Get-NaVol vol* }
Controller: dunn
Name State TotalSize Used Available Dedupe FilesUsed FilesTotal Aggregate
---- ----- --------- ---- --------- ------ --------- ---------- ---------
vol0 online 101.4 GB 14% 86.7 GB True 83k 4M aggr0
vol1 online 16.0 GB 5% 15.2 GB True 142 623k aggr1
vol1clone online 16.0 GB 5% 15.2 GB True 142 623k aggr1
vol2 online 180.0 GB 53% 83.8 GB True 242 6M aggr1
vol2clone online 180.0 GB 93% 12.9 GB True 214 6M aggr1
vol3 online 420.0 MB 0% 419.6 MB True 143 16k aggr1
Controller: benson
vol0 online 86.2 GB 5% 82.1 GB False 14k 4M aggr0
vol1 online 901.5 GB 62% 344.6 GB False 45k 28M aggr1
vol4 online 150.0 GB 80% 29.6 GB False 238 5M aggr1
>> Also, based on your expression statement, when you are adjusting the size you use DataSize "0.0". What is that actually doing behind the scenes?
The Toolkit cmdlet ConvertTo-FormattedNumber is a convenience cmdlet used primarily by the data formatters, though you can use it directly as well. The "DataSize" parameter instructs the cmdlet to include units like MB or GB. "0.0" is the formatting string passed to String.Format() (http://msdn.microsoft.com/en-us/library/0c899ak8.aspx); in this case, we're just requesting a single digit to the right of the decimal point.