Pré-requis: * PsExec de SysInternals Suite * PowerShell 2.0 ou plus pour les modules PowerShell disposent sur l'ordinateur distant (s)
Premièrement, permettent PSRemoting via PsExec:
psexec \\[computer name] -u [admin account name] -p [admin account password] -h -d powershell.exe "enable-psremoting -force"
Les Le script PowerShell suivant fera l'affaire, sans WMI, via PowerShell Sessions à la place, et le fera pour autant d'ordinateurs que vous le souhaitez:
Voici le script du pilote:
$computerNames = @("computer1", "computer2");
$computerNames | foreach {
$session = New-PSSession -ComputerName $_;
Invoke-Command -Session $session -FilePath c:\path\to\Extend-AllPartitionsOnAllDisks.ps1
Remove-PSSession $session
}
Et voici 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...";
}
}
Je ne pense pas que ce soit possible avec WMI seul. [Relié] (http://stackoverflow.com/q/4797173/1630171). Sous Windows 8/Server 2012 et plus récent, vous pouvez également essayer ['Resize-Partition'] (https://technet.microsoft.com/fr-fr/library/hh848680.aspx). –
Avez-vous essayé avec powershell remoting ou PSexec.exe? –
@SandeepKs De la question: * "Ces VM n'ont pas WinRM activé et ce n'est pas une option." * –