For example, to create ten dummy files c:\temp\file* with the size of 1GiB :
1 |
0..9 | foreach {fsutil file createnew "c:\temp\file$_" 1073741824} |
This script will check a disk’s free space and send a warning if the server has dropped below the limit you have specified.
The settings are in a XML file. The main entity is the filesystem – let’s say a drive letter or disk. Each disk must be defined as an element, which includes values such as the hostname, limit, and list of recipents.
Both files for this solution must be in the same folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
$ScriptPath = $MyInvocation.MyCommand.Path $RunPath = Split-Path $ScriptPath $Settings = [xml](Get-Content "$RunPath\watchdog.config.xml") $Log = "$RunPath\$($Settings.freeSpaceWatchdog.globalSettings.log)" $SMTPServer = $Settings.freeSpaceWatchdog.globalSettings.smtpserver $EmailSender = $Settings.freeSpaceWatchdog.globalSettings.emailSender $Timestamp = Get-Date -Format "yyyy.MM.dd HH:mm" foreach ($Item in $Settings.freeSpaceWatchdog.filesystem) { $ComputerName = $($Item.Hostname) $Disk = $($Item.Volume) $Limit = [math]::round($($Item.Limit), 2) $EmailRecipients = $($Item.EmailRecipients) $Data = Get-WmiObject Win32_LogicalDisk -ComputerName $ComputerName -Filter "DeviceID='$Disk'" | Select-Object FreeSpace, Size $Size = [math]::round($Data.Size / 1GB, 2) $FreeSpace = [math]::round($Data.FreeSpace / 1GB, 2) if ($FreeSpace -le $Limit) { "$Timestamp - Warning - $Comptername disk $Disk, limit $Limit, freespace $Freespace" >> $Log Send-MailMessage ` -From $EmailSender ` -To $EmailRecipients ` -SmtpServer $SMTPServer ` -Subject "$Computername disk $Disk warning" ` -Body "On $ComputerName disk $Disk has exceeded the limit $Limit GB.`n`nSize $Size GB`nFree space $FreeSpace GB" ` -Priority High } else { "$Timestamp - OK - $Computername disk $Disk, limit $Limit, freespace $Freespace" >> $Log } } |
Here is an overview:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<freeSpaceWatchdog> <globalSettings> <smtpserver>mailer15</smtpserver> <emailSender>freespacelimit@mydomain.com</emailSender> <log>freespacewatchdog.log</log> </globalSettings> <filesystem volume="C:"> <hostname>mbx01</hostname> <limit>50</limit> <emailRecipients>helpdesk@mydomain.com</emailRecipients> </filesystem> <filesystem volume="E:"> <hostname>mbx02</hostname> <limit>70</limit> <emailRecipients>helpdesk@mydomain.com</emailRecipients> </filesystem> </freeSpaceWatchdog> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Param ( [Parameter(Mandatory=$false, ValueFromPipeline=$true)] [string]$ComputerName = $env:COMPUTERNAME ) $PhysicalDevices = Get-WmiObject Win32_DiskDrive -ComputerName $ComputerName foreach ($Device in $PhysicalDevices) { $DiskIndex = $Device.Index $DeviceModel = $Device.Model $DeviceSize = [math]::truncate($Device.Size / 1GB) Write-Host "`nDISK $DiskIndex $DeviceModel [$DeviceSize GB]" $Partitions = Get-WmiObject Win32_DiskPartition -ComputerName $ComputerName | Where-Object {$_.DiskIndex -eq $DiskIndex} foreach ($Partition in $Partitions) { $ID = $Partition.Index $Offset = $Partition.StartingOffset $PartitionSize = [math]::truncate($Partition.Size / 1GB) if ($Offset % 4096) { Write-Host "+ PARTITION $ID [$PartitionSize GB] is not correctly aligned, offset is $Offset bytes"` -BackgroundColor DarkRed } else { Write-Host "+ PARTITION $ID [$PartitionSize GB] is correctly aligned, offset is $Offset bytes" } } } |
1 2 3 4 5 6 7 8 9 |
PS C:\Temp>PS C:\temp> .\Get-PartitionOffset.ps1 -ComputerName pc12398 DISK 0 ADATA SSD S511 120GB ATA Device [111 GB] + PARTITION 0 [0 GB] is correctly aligned, offset is 1048576 bytes + PARTITION 1 [111 GB] is correctly aligned, offset is 105906176 bytes DISK 1 WDC WD20EURS-63S48Y0 ATA Device [1863 GB] + PARTITION 0 [1863 GB] is correctly aligned, offset is 1048576 bytes PS C:\temp> |
1 2 3 4 5 6 7 8 9 10 11 12 |
PS C:\temp> .\Get-PartitionOffset.ps1 -ComputerName exchcas02 DISK 0 VMware Virtual disk SCSI Disk Device [64 GB] + PARTITION 0 [0 GB] is correctly aligned, offset is 1048576 bytes + PARTITION 1 [64 GB] is correctly aligned, offset is 105906176 bytes DISK 1 VMware Virtual disk SCSI Disk Device [1999 GB] + PARTITION 0 [1999 GB] is correctly aligned, offset is 1048576 bytes DISK 2 VMware Virtual disk SCSI Disk Device [14 GB] + PARTITION 0 [14 GB] is correctly aligned, offset is 1048576 bytes PS C:\temp> |
1 2 3 4 5 6 7 8 9 10 11 |
PS C:\temp> .\Get-PartitionOffset.ps1 DISK 0 SAMSUNG SSD PM810 FDE 2.5" 128GB ATA Device [119 GB] + PARTITION 0 [119 GB] is correctly aligned, offset is 2097152 bytes DISK 1 SD Memory Card [30 GB] + PARTITION 0 [30 GB] is correctly aligned, offset is 4194304 bytes DISK 2 Corsair Flash Voyager USB Device [7 GB] + PARTITION 0 [7 GB] is correctly aligned, offset is 40960 bytes PS C:\temp> |
source:
http://pctuning.tyden.cz/software/ladeni-windows/17030-optimalizace-windows-7-pro-ssd-co-funguje-a-co-ne?start=2
http://lifehacker.com/5837769/make-sure-your-partitions-are-correctly-aligned-for-optimal-solid-state-drive-performance