快速調整 User Profile Disk 磁碟與分割區大小
紅色部份為應調整參數
$ExtendDiskSize = 16; #in GB
$DiskPartCommandFileName = ((Get-Location).Path + '\DiskPartCommand.txt');
$ExtendDiskSize = ($ExtendDiskSize*1024*1024*1024);
$VHDxs = Get-ChildItem -path 'C:\VirtualDisks\Pool' -Recurse -Filter "*.vhdx" | select FullName;
ForEach ($VHDx in $VHDxs) {
$oFile = New-Object System.IO.FileInfo $VHDx.FullName;
try {
$oStream = $oFile.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None);
if ($oStream) {
$oStream.Close();
};
$FileOpen = $False;
} catch {
# file is locked by a process.
$FileOpen = $True;
};
if ($FileOpen -eq $False) {
if ( ((Get-VHD $VHDx.FullName).Size) -lt $ExtendDiskSize ) {
Resize-VHD -Path $VHDx.FullName -SizeBytes $ExtendDiskSize
$DiskNumber = (Mount-VHD $VHDx.FullName -PassThru | Get-Disk).Number;
$DiskPartCommand = '';
$DiskPartCommand += "select disk " + $DiskNumber + "`r`n";
$DiskPartCommand += "select part 1`r`n";
$DiskPartCommand += "extend`r`n";
$DiskPartCommand += "exit`r`n";
$DiskPartCommand | Out-File $DiskPartCommandFileName -Encoding ASCII
Start-Process -Wait -FilePath 'C:\Windows\System32\diskpart.exe' -ArgumentList ('/s "' + $DiskPartCommandFileName + '"')
Dismount-VHD $VHDx.FullName
Remove-Item $DiskPartCommandFileName
};
};
};
沒有留言:
張貼留言