Hi,
I am trying to get the execute the below script and I am unable to get the output from below,
Please help!!
$mydiskxtend=@"
Get-WmiObject Win32_DiskDrive | ForEach-Object {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | ForEach-Object {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | ForEach-Object {
New-Object -Type PSCustomObject -Property @{
Name = $env:computername
Index = $disk.Index
Disk = $disk.DeviceID
Status = $disk.Status
DiskModel = $disk.Model
Serial = $disk.SerialNumber
Partition = $partition.Name
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
"Size(GB)" = [math]::round($_.Size/1024/1024/1024,2)
"FreeSpace(GB)" = [math]::round($_.FreeSpace/1024/1024/1024,2)
"Free(%)" = [math]::Round(((100*($_.FreeSpace))/($_.Size)),0)
"UsedSpace(GB)" = [math]::Round(((($_.Size / 1GB))-($_.FreeSpace / 1GB)),0)
}
}
}
} | Sort-Object Index | Select-Object Name, Index, Disk, DriveLetter, VolumeName, Serial, DiskModel, "Size(GB)", "UsedSpace(GB)", "FreeSpace(GB)", "Free(%)" | Format-Table * -AutoSize
# Write the commands to a temporary file
"RESCAN" | Out-File -FilePath "C:\DiskPart.txt" -Encoding ASCII
"SELECT Volume D" | Out-File -FilePath "C:\DiskPart.txt" -Append -Encoding ASCII
"EXTEND" | Out-File -FilePath "C:\DiskPart.txt" -Append -Encoding ASCII
"EXIT" | Out-File -FilePath "C:\DiskPart.txt" -Append -Encoding ASCII
# Run DiskPart with the script
Start-Process "DiskPart.exe" -ArgumentList "/s C:\DiskPart.txt" -Wait
# Delete the script file after execution
Remove-Item -Path "C:\DiskPart.txt" -Force
"@
Invoke-VMScript -VM $serv -ScriptText $mydiskxtend -ScriptType Powershell -GuestUser "admin" -GuestPassword P@ssw1rd -Verbose