VMware Cloud Community
1CrackedHead
Contributor
Contributor
Jump to solution

Unable to resize VM disk after VMWare tools update

I have a PowerCLI script to resize a VM drive and expand it in the Windows OS. After updating guests from tools version 10305 (old) to version 10346. The script fails with this error:

Set-HardDisk : 2/4/2020 8:20:58 AM Set-HardDisk Error occured while executing script on guest OS in VM 'vsdistcdap02rja'. Could not locate "Bat" script interpreter in any of the expected locations.

Probably you do not have enough permissions to execute command within guest.

I have recreated this issue by just updating tools. Anyone else run into this? Here is my script to make the changes:

Clear-Host

$server= "SERVERNAME"

$NewTotalDiskSize=104

$scripttorun = 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

&$scripttorun

Connect-VIServer -Server VcenterServer.company.com -alllinked

Get-HardDisk -VM $server | Where-Object {$_.Name -eq "Hard disk 1"} | Set-HardDisk -CapacityGB $NewTotalDiskSize -Confirm:$false -ResizeGuestPartition

I can accomplish this with the GUI, but the task laid out before me is to adjust the disk size of 500 servers. The above script is the stripped down commands.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I would use

Get-Credential -Message 'Enter credentials' -UserName "$($env:USERDOMAIN)\$($env:USERNAME)"

or

Get-Credential -Message 'Enter credentials' -UserName "$($env:USERNAME)@$($env:USERDNSDOMAIN)"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

7 Replies
LucD
Leadership
Leadership
Jump to solution

Were the VMware Tools restarted after the upgrade?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You might be experiencing the same issue as reported in Re: Invoke-VMScript failed when guestcredential is not provided

Can you try adding the GuestCredential (or GuestUser/GuestPassword) parameters on the Set-Harddisk?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
1CrackedHead
Contributor
Contributor
Jump to solution

No the guest was not restarted. But it has failed on other guests that have been rebooted.

Reply
0 Kudos
1CrackedHead
Contributor
Contributor
Jump to solution

I added this to the script:

Clear-Host

$server= "SERVERNAME"

$NewTotalDiskSize=104

$scripttorun = 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

&$scripttorun

$Creds = Get-Credential "$env:USERDNSDOMAIN/$env:USERNAME"

Connect-VIServer -Server VcenterServer.company.com -alllinked

Get-HardDisk -VM $server | Where-Object {$_.Name -eq "Hard disk 1"} | Set-HardDisk -CapacityGB $NewTotalDiskSize -Confirm:$false -ResizeGuestPartition -GuestCredential $creds

Now I get this error:

Set-HardDisk : 2/4/2020 2:47:16 PM Set-HardDisk Failed to authenticate with the guest operating system using the supplied credentials.

At line:17 char:71


I tried several credentials that I know can login to the OS. Did I add that part to my script like you would have?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I would use

Get-Credential -Message 'Enter credentials' -UserName "$($env:USERDOMAIN)\$($env:USERNAME)"

or

Get-Credential -Message 'Enter credentials' -UserName "$($env:USERNAME)@$($env:USERDNSDOMAIN)"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

1CrackedHead
Contributor
Contributor
Jump to solution

PERFECT it worked! Thanks

Clear-Host

$server= "Hostname"

$NewTotalDiskSize=108

$scripttorun = 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

&$scripttorun

$Creds = Get-Credential -Message 'Enter credentials' -UserName "$($env:USERDOMAIN)\$($env:USERNAME)"

Connect-VIServer -Server Vcenter.company.com -alllinked

Get-HardDisk -VM $server | Where-Object {$_.Name -eq "Hard disk 1"} | Set-HardDisk -CapacityGB $NewTotalDiskSize -Confirm:$false -ResizeGuestPartition -GuestCredential $creds

Reply
0 Kudos
SLGizmo
Contributor
Contributor
Jump to solution

Does not work for me and I am logged in with full admin account and run the additional command and logged in through the pop up and still the same error.

Reply
0 Kudos