2014-10-07 81 views
0

現在下面是我的腳本添加日期到我的輸出在此下方PS腳本

foreach ($Server in (Get-Content C:\psfiles\Winservers.txt)){ 
    Get-WmiObject win32_logicalDisk -ComputerName $Server | Select @{ 
     Expression={$Server};label="ServerName"},DeviceID,Volumename ,@{Expression={ 
     $_.Size /1Gb -as [int]};Label="Total Size(GB)"},@{Expression={($_.Size /1Gb 
     -as [int]) 
     - ($_.Freespace/ 1Gb -as [int])};Label="InUse Size (GB)"} , 
      @{Expression={$_.Freespace/1Gb -as  [int]};Label="FreeSize(GB)"}, 
      @{Expression={(($_.Freespace /1Gb -as [float])/($_.Size/1Gb -as    
      [float]))*100};Label="FreeSpace (%)"},$(Get-Date -format 'd') 
     | format-table 

權now..i得到的輸出如下

servername deviceid volumename totalsize............10/6/2014 

srv1   c:  data   100     null 

srv2   d:  bkup   50     null 

我想要得到的結果作爲

servername  deviceid volumename totalsize............createdt 

srv1    c:  data   100   10/16/2014 

srv2    d:  bkup   50    10/6/2014 

在此先感謝!

回答

0

我看到兩者之間唯一的區別是格式化空間和最後一列與日期。

第一名Format-Table在前面標註所有屬性。 Get-Date函數只是返回當前日期。這就是爲什麼你沒有看到日期在列中。

這裏是一個link,它向你展示瞭如何正確地格式化和標記表格。

+0

沒有實際的第一個結果我得到的日期作爲列名我想它作爲創建日期和列中的第二個結果中的實際日期。 – schinni9 2014-10-07 13:18:11