PowerShell脚本不将数据放入.CSV

时间:2016-06-07 19:27:20

标签: windows powershell

我正在构建一个脚本来获取驱动器空间数据。该脚本完成且没有错误并创建excel文档但是,文件大小为0 kb而没有任何类别。我无法弄清楚出了什么问题。

Set-ExecutionPolicy Unrestricted -Force
$OldReports = (Get-Date).AddDays(-7)

Get-ChildItem C:\myscripts\*.* | `
Where-Object { $_.LastWriteTime -le $OldReports} | `
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue

$LogDate = get-date -f yyyyMMddhhmm

$File = Get-Content -Path C:\myscripts\servers1.txt

$DiskReport = ForEach ($Servernames in ($File)) 

{Get-WmiObject win32_logicaldisk <#-Credential $RunAccount#> `
-ComputerName $Servernames -Filter "Drivetype=3" `
-ErrorAction SilentlyContinue | 

Where-Object {   ($_.freespace/$_.size) -le '0.1'}

} 

$DiskReport | 

Select-Object @{Label = "Server Name";Expression = {$_.SystemName}},
@{Label = "Drive Letter";Expression = {$_.DeviceID}},
@{Label = "Total Capacity (GB)";Expression = {"{0:N1}" -f( $_.Size /     1gb)}},
@{Label = "Free Space (GB)";Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) }},
@{Label = 'Free Space (%)'; Expression = {"{0:P0}" -f       ($_.freespace/$_.size)}} |

Export-Csv -path "C:\MyScripts\DiskReport_$logDate.csv" -NoTypeInformation

它拉取服务器的文件是否需要是特定格式?截至目前,我只有机器名.domain

0 个答案:

没有答案
相关问题