Speicherplatz anzeigen (FreeDisk): Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
Zeile 14: Zeile 14:
 
Function Get-FreeDiskSpace {
 
Function Get-FreeDiskSpace {
 
     [CmdletBinding()]
 
     [CmdletBinding()]
 
+
 
     param(
 
     param(
 
     [Parameter(Position=0,mandatory=$true)]
 
     [Parameter(Position=0,mandatory=$true)]
 
     [string] $Hostname
 
     [string] $Hostname
 
     )
 
     )
 
+
 
     process {
 
     process {
         Get-WMIObject Win32_Logicaldisk -filter "deviceid='C:'" -ComputerName $Hostname | Select PSComputername,DeviceID,
+
         $Volumes = (Get-Volume -CimSession $Hostname).DriveLetter
        @{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},
+
 
        @{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}
+
        Foreach ($Volume in $Volumes) {
 +
            $Volume = $Volume + ":"
 +
 
 +
            Get-WMIObject Win32_Logicaldisk -filter "deviceid='$Volume'" -ComputerName $Hostname | Select PSComputername,DeviceID,
 +
            @{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},
 +
            @{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}
 +
        }
 
     }
 
     }
 
}
 
}

Version vom 2. März 2018, 11:27 Uhr

Zeigt alle Laufwerke und dessen freien Speicherplatz an.

Version 1

$Hostname = Read-Host "Geben Sie den Hostname des Systems an:"
Get-WMIObject Win32_Logicaldisk -filter "deviceid='C:'" -ComputerName $Hostname | Select PSComputername,DeviceID,
@{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},
@{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}


Version 2

Function Get-FreeDiskSpace {
    [CmdletBinding()]
 
    param(
    [Parameter(Position=0,mandatory=$true)]
    [string] $Hostname
    )
 
    process {
        $Volumes = (Get-Volume -CimSession $Hostname).DriveLetter
 
        Foreach ($Volume in $Volumes) {
            $Volume = $Volume + ":"
 
            Get-WMIObject Win32_Logicaldisk -filter "deviceid='$Volume'" -ComputerName $Hostname | Select PSComputername,DeviceID,
            @{Name="SizeGB";Expression={$_.Size/1GB -as [int]}},
            @{Name="FreeGB";Expression={[math]::Round($_.Freespace/1GB,2)}}
        }
    }
}