Предпосылки: * PsExec от Sysinternals Suite * PowerShell 2.0 или выше для модулей PowerShell имеют на удаленном компьютере (ы)
Во-первых, включить PSRemoting с помощью PsExec:
psexec \\[computer name] -u [admin account name] -p [admin account password] -h -d powershell.exe "enable-psremoting -force"
В следующий сценарий PowerShell выполнит трюк без WMI через сеансы PowerShell вместо этого и сделает это на столько компьютеров, сколько вы хотите:
Вот сценарий драйвера:
$computerNames = @("computer1", "computer2");
$computerNames | foreach {
$session = New-PSSession -ComputerName $_;
Invoke-Command -Session $session -FilePath c:\path\to\Extend-AllPartitionsOnAllDisks.ps1
Remove-PSSession $session
}
А вот Extend-AllPartitionsOnAllDisks.ps1:
Import-Module Storage;
$disks = Get-Disk | Where FriendlyName -ne "Msft Virtual Disk";
foreach ($disk in $disks)
{
$DiskNumber = $disk.DiskNumber;
$Partition = Get-Partition -DiskNumber $disk.DiskNumber;
$PartitionActualSize = $Partition.Size;
$DriveLetter = $Partition.DriveLetter;
$PartitionNumber = $Partition.PartitionNumber
$PartitionSupportedSize = Get-PartitionSupportedSize -DiskNumber $DiskNumber -PartitionNumber $PartitionNumber;
if ($disk.IsReadOnly)
{
Write-Host -ForegroundColor DarkYellow "Skipping drive letter [$DriveLetter] partition number [$PartitionNumber] on disk number [$DiskNumber] because the disk is read-only!";
continue;
}
if ($PartitionActualSize -lt $PartitionSupportedSize.SizeMax) {
# Actual Size will be greater than the partition supported size if the underlying Disk is "maxed out".
# For example, on a 50GB Volume, if all the Disk is partitioned, the SizeMax on the partition will be 53684994048.
# However, the full Size of the Disk, inclusive of unpartition space, will be 53687091200.
# In other words, it will still be more than partition and unlikely to ever equal the partition's MaxSize.
Write-Host -ForegroundColor Yellow "Resizing drive letter [$DriveLetter] partition number [$PartitionNumber] on disk number [$DiskNumber] because `$PartitionActualSize [$PartitionActualSize] is less than `$PartitionSupportedSize.SizeMax [$($PartitionSupportedSize.SizeMax)]"
Resize-Partition -DiskNumber $DiskNumber -PartitionNumber $PartitionNumber -Size $PartitionSupportedSize.SizeMax -Confirm:$false -ErrorAction SilentlyContinue -ErrorVariable $resizeError
Write-Host -ForegroundColor Green $resizeError
}
else {
Write-Host -ForegroundColor White "The partition is already the requested size, skipping...";
}
}
Я не думаю, что это возможно с помощью WMI в одиночку. [Релевантные] (http://stackoverflow.com/q/4797173/1630171). В Windows 8/Server 2012 и новее вы также можете попробовать ['Resize-Partition'] (https://technet.microsoft.com/en-us/library/hh848680.aspx). –
Пробовал ли с помощью PowerShell удален или PSexec.exe? –
@SandeepKs С вопросом: * «У этих виртуальных машин нет поддержки WinRM, и это не вариант». * –