Je suis encore en train d'apprendre à me débrouiller avec PS et je cherche quelques recommandations. J'ai travaillé sur script pour trouver si C est < ou = 20GB et lister les endroits habituels comme Documents et Downloads et mesurer leur taille. Maintenant que tout est trié, je veux mettre chaque dossier qu'il vérifie dans un seul output.txt mais je ne sais pas comment. Je pensais d'une certaine manière lier tous mes Get-Childitems ensemble mais je ne sais pas par où commencer. Voici ce que j'ai obtenu jusqu'à présent.
#Check size of C and if its < or = 20GB
$FreeSpace = Get-PSDrive -Name 'c' | Select-Object Free
Write-Host "Free Space On C Left"
$TotalFreeSpace = $FreeSpace.free
$num = $TotalFreeSpace
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
$condition = $TotalFreeSpace
if ( $condition -le 20 )
{
Write-Output "The C Drive's free space is > or = 20GB"
}
#File Location Measures
$UserName = $env:UserName
Write-Host "Desktop Folder Size"
$Desktop = Get-Childitem C:\LOCAL\$UserName\Desktop | Measure-Object -Sum Length
$num = $Desktop.sum
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
Write-Host "My Documents Folder Size"
$Documents = Get-Childitem C:\LOCAL\$UserName\'My Documents' | Measure-Object -Sum Length
$num = $Documents.sum
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
Write-Host "Downloads Folder Size"
$Downloads = Get-Childitem C:\Users\$UserName\Downloads | Measure-Object -Sum Length
$num = $Downloads.sum
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
Write-Host "Picture Folder Size"
$Pictures = Get-Childitem C:\LOCAL\$UserName\'My Documents'\'My Pictures' | Measure-Object -Sum Length
$num = $Pictures.sum
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
Write-Host "Music Folder Size"
$Music = Get-Childitem C:\LOCAL\$UserName\'My Documents'\'My Music' | Measure-Object -Sum Length
$num = $Music.sum
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
Write-Host "Videos Folder Size"
$Videos = Get-Childitem C:\LOCAL\$UserName\'My Documents'\'My Videos' | Measure-Object -Sum Length
$num = $Videos.sum
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
Write-Host "Recycle Bin Size"
($RecycleBin = Get-ChildItem -LiteralPath 'C:\$Recycle.Bin' -File -Force -Recurse -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
$num = $RecycleBin.sum
if ($num -lt 1TB) {
$num = $num / 1GB
$num = "{0:n2}" -f $num
"$num GB"
}
| Out-File -Path C:\LOCAL\$UserName\Desktop\$UserName'CDriveFullOutput'.txt
#Thanks to Lee_Dailey for Dev help!