I am writing a script that return drive size/freespace/path,volume,etc. for Exchange database drives and returns output like so:
.\GetExchangeDrive.ps1
Database : DB1
Type : DatabaseDrove
Server : Server1
Volume : E:\
Path : E:\Databases\DB1\
SizeGB : 30.00
FreeGB : 29.61
Free% : 98.70 %
The script returns properties as objects so I can manipulate the output (sort by freespace, size ,server,etc)
My objective is for the script to return all properties as objects so I can save to variable/manipulate if I wanted to but I also want the output to the screen to be limited and in a certain format similar to this:
.\GetExchangeDrive.ps1
Database Server Path SizeGB FreeGB Free%
-------- ------ ------------- ------ ------ -----
DB1 Server1 E:\Databases\DB1\ 30.00 29.61 98.73 %
The above is result of format-table but the problem with is that it does not save the output as objects so I cannot manipulate the output.
My question is with built-in Powershell commands such as Get-Item; How are these commands written that when you run the command it only displays 4 properties on the screen but in reality returns several other properties as objects that are hidden on the screen. I want to be able to write my scripts in this manner where all properties are returned as objects but only the important properties are displayed on the screen in a nice format.
Example:
Running the following saves the get-item result to a variable
PS C:\> $c = Get-Item rsatcustominstaller.log
When displayed it only displays the important properties in a compact format
PS C:\> $c
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 5/20/2013 8:38 PM 305 rsatcustominstaller.log
But in reality $c holds all properties that get-item offered.
PS C:\> $c | select *
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\rsatcustominstaller.log
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\
PSChildName : rsatcustominstaller.log
PSDrive : C
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
VersionInfo : File: C:\rsatcustominstaller.log
InternalName:
OriginalFilename:
FileVersion:
FileDescription:
Product:
ProductVersion:
Debug: False
Patched: False
PreRelease: False
PrivateBuild: False
SpecialBuild: False
Language:
BaseName : rsatcustominstaller
Mode : -a---
Name : rsatcustominstaller.log
Length : 305
DirectoryName : C:\
Directory : C:\
IsReadOnly : False
Exists : True
FullName : C:\rsatcustominstaller.log
Extension : .log
CreationTime : 5/20/2013 8:38:06 PM
CreationTimeUtc : 5/21/2013 3:38:06 AM
LastAccessTime : 5/20/2013 8:38:06 PM
LastAccessTimeUtc : 5/21/2013 3:38:06 AM
LastWriteTime : 5/20/2013 8:38:06 PM
LastWriteTimeUtc : 5/21/2013 3:38:06 AM
Attributes : Archive