无法检索Powershell中文件共享的已用空间和可用空间。我目前正在使用以下Powershell脚本

时间:2019-03-14 17:42:25

标签: powershell-v4.0

Function CleanUp-PSDrive {
    Get-PSDrive -PSProvider FileSystem | Where { $_.Name -in (69..90 | ForEach-Object { [char]$_ })} | Remove-PSDrive
}

$Csv = Import-Csv "C:\Users\503080876\Documents\New folder\new.txt"

$Csv.Name | ForEach-Object -Begin { $Letter = 69 } {

New-PSDrive -Root  $_ -Name([char]$Letter) -PSProvider FileSystem



  #select root,used | 

 select used,free | export-csv "C:\Users\503080876\Documents\New folder\New1.txt"




    if ($Letter -lt 90) 
    { 
      $Letter++ 
    } 
    else 
    { 
        CleanUp-PSDrive
        $Letter = 69
    }
} -End { CleanUp-PSDrive }

1 个答案:

答案 0 :(得分:0)

Function CleanUp-PSDrive {
Get-PSDrive -PSProvider FileSystem | Where { $_.Name -in (69..90 | ForEach-Object { [char]$_ })} | Remove-PSDrive

}

$Csv = Import-Csv "path"

$ Csv.Name | ForEach-Object -Begin {$ Letter = 69} {

new-PSDrive -Root $ _ -Name([char] $ Letter)-PSProvider FileSystem -Persist

if ($Letter -lt 90) 
{ 
  $Letter++ 
} 
else 
{ 
    CleanUp-PSDrive
    $Letter = 69
}
} -End { CleanUp-PSDrive } | 

选择对象@ {name =“文件共享名”; expression = {$$ em ..'DisplayRoot'}},@ {name =“ Total(GB)”; expression = {($ .free + $ .used)/ 1GB}},@ {name =“ Used(GB)”; expression = {$ .used / 1GB}},@ {name =“ Free(GB)” ; expression = {$ _。free / 1GB}} |

export-csv“路径” -NoTypeInformation