【发布时间】:2018-03-15 21:34:27
【问题描述】:
这个简单的 PowerShell 脚本“填充”了 USB 闪存驱动器的坏扇区。但我需要用包含 0x00(所有位为零)和 0x255(所有位为 1)的文件填充驱动器。如何在 PowerShell 中使用十六进制?
function filler {
Param( [byte]$hex )
$filearray = @()
$count = 1
$freespace = Get-PSDrive H
$maxfiles = [int]($freespace.Free / 1048576)
do {
$randomnum = Get-Random -Minimum 100000000 -Maximum 999999999
"$hex" * 1048576 | Out-File $randomnum
$filecontent = Get-Content $randomnum -Raw
if ($filecontent -notcontains ('$hex')) {
# do nothing because the content is incorrect
} else {
$filearray += $randomnum
}
$count++
} while ($count -le $maxfiles)
foreach ($filename in $filearray) {
Remove-Item $filename
}
}
filler -hex 0x00
filler -hex 0xFF
【问题讨论】:
-
[byte]$hex = 0xff; "$hex" * 5并没有达到您的预期。它创建字符串“255255255255255”(将整数值 0xFF 的字符串表示重复 5 次)。
标签: windows powershell windows-10