|
注册登录后全站资源免费查看下载
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- <#*,:&cls
- [url=home.php?mod=space&uid=11189]@echo[/url] off
- cd /d "%~dp0"
- set "batchfile=%~f0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create([IO.File]::ReadAllText($env:batchfile,[Text.Encoding]::GetEncoding(0) )) )"
- pause
- exit /b
- #>
- # 文件大小
- $fillSize = 5gb
- # 目标磁盘
- $drvLetter = "c:"
- # 数据类型:1=以随机填充,2=指定填充字节
- $fillType = 1
- # 指定字节
- [byte]$fillByte = 0x88
- # 循环次数
- $fillCount = 300
- $drvInfo = New-Object System.IO.DriveInfo -ArgumentList $drvLetter
- $drvInfo
- if (-not $drvInfo.IsReady) {
- Write-Error '该磁盘未就绪'
- return
- }
- $buff = New-Object 'byte[]' -ArgumentList 1mb
- if ($fillType -eq 1) {
- $rnd = New-Object Random
- $rnd.NextBytes($buff)
- }elseif ($fillType -eq 2) {
- for ($i = 0; $i -lt $buff.Count; $i++) {
- $buff[$i] = $fillByte
- }
- }
- $listFills = New-Object 'System.Collections.Generic.List[string]'
- for ($i = 1; $i -lt $fillCount+1; $i++) {
- $listFills.Clear()
- try {
- "第 ${i} 次填充"
- while ($drvInfo.AvailableFreeSpace -gt $fillSize) {
- $outName = [Guid]::NewGuid().ToString()
- $outFile = [IO.Path]::Combine($drvInfo.RootDirectory.FullName, $outName)
- $listFills.Add($outFile)
- try {
- $stream = New-Object System.IO.FileStream -ArgumentList ($outFile, 'Create', 'Write', 'Read', 1mb)
- $ctr = 0
- do {
- $stream.Write($buff, 0, $buff.Count)
- $ctr += $buff.Count
- } until ($ctr -ge $fillSize)
- $stream.SetLength($fillSize)
- } finally {
- if ($stream) {
- $stream.Close()
- $stream = $null
- }
- }
- }
- } finally {}
- "正在删除文件"
- Remove-Item -LiteralPath $listFills -Force
- trap {}
- }
复制代码
此代码只写不读,填满自动删除。如果中断需要手动删除残留文件,它是不会自动删除的。
工作原理:固态硬盘有PE次数,一旦被消耗完硬盘将变得不可靠。
使用方法:把代码另存为bat文件即可,测试内容自己修改后运行。
|
|