vCenter ?? $vm->ipAddress?->host?->datacenter?->vCenter; if (!$vcenter) { return 'vCenter_Not_Found'; } if (!$this->vcenter->loginServer($vcenter)) { return 'Login_Again'; } // Use provided guest credentials, fallback to VM stored credentials $user = $guestUser ?: (string) $vm->user; $pass = $guestPassword ?: (string) $vm->getRawOriginal('password'); return $this->vcenter->changeIpVM( (string) $vm->name, // -VMName (Get-VM -Name) (string) $vm->vmware_id, // VMware ID (Windows -Id pattern) $ipAddress, $gateway, $osType, $user, // -GuestUser $pass, // -GuestPassword (plaintext) $dns, (string) $vm->hostname ); } catch (\Throwable $e) { return 'Error: ' . $e->getMessage(); } } }