Powershell获取日期/星期/用户名/机器名/磁盘信息
$now=get-date
$week=($now).DayOfWeek
$date=$now.ToString('yyyy-MM-dd HH:mm:ss.ff')
Write-Output "$date $week $env:userName $env:COMPUTERNAME"
---------------------------------------------------------------------------------------------------
$DiskCount = ((Get-WmiObject -Class Win32_DiskDrive).Caption).count
#获取磁盘分区大小
$DiskInfo = Get-WmiObject -Class Win32_LogicalDisk
echo "--------------------统计磁盘分区状况-------------------------"
echo " 驱动器号 卷标 分区空间 可用空间 文件系统 "
foreach ($Drivers in $DiskInfo)
{
$PartitionID = $Drivers.DeviceID
$PartitionSize = "{0:N2}GB" -f ($Drivers.Size/1GB)
$PartitionFreeSize = "{0:N2}GB" -f ($Drivers.FreeSpace/1GB)
$PartitionName = $Drivers.VolumeName
$PartitionFS = $Drivers.FileSystem
echo " $PartitionID $PartitionName $PartitionSize $PartitionFreeSize $PartitionFS "
}
PS C:\Windows\system32> D:\powershell\无标题2.ps1
--------------------统计磁盘分区状况-------------------------
驱动器号 卷标 分区空间 可用空间 文件系统
C: 系统盘 118.27GB 16.28GB NTFS
D: 工作盘 100.00GB 76.48GB NTFS
E: 娱乐盘 150.00GB 26.63GB NTFS
F: 新加卷 91.86GB 78.47GB NTFS