mk_ultra's Posts

Can Get-ESXCLI be used to read the contents of text/config files on a host? Trying to read the SSHD config: /usr/lib/vmware/openssh/bin/sshd -T
Yes, the boot disk is on 0. I got one VM to boot successfully running Paravirtual on SCSI 0 by using the linked KB article. Is it best practice not to use Paravirtual for Windows boot disks? Everywhe... See more...
Yes, the boot disk is on 0. I got one VM to boot successfully running Paravirtual on SCSI 0 by using the linked KB article. Is it best practice not to use Paravirtual for Windows boot disks? Everywhere I'm reading says Paravirtual is essentially the new gold standard for VM SCSI controllers.
Hello, I am working on a script to automate this process in order to change SCSI controller 0 to Paravirtual: https://kb.vmware.com/s/article/1002149 I nearly have a full working script, but the o... See more...
Hello, I am working on a script to automate this process in order to change SCSI controller 0 to Paravirtual: https://kb.vmware.com/s/article/1002149 I nearly have a full working script, but the only part I'm struggling with is simulating a Windows logon event in order to install the Paravirtual SCSI controller drivers. Currently what I am trying is using a New-PSSession to invoke commands in the guest OS that might rescan for device drivers. So far I have tried invoking the following commands: Get-PnPDevice pnputil.exe /scan-devices pnputil.exe /enum-drivers $Disks = (Get-Disk).number Update-Disk $Disks rundll32.exe advpack.dll,LaunchINFSectionEx "C:\Program Files\Common Files\VMware\Drivers\pvscsi\Win8\pvscsi.inf",,"C:\Program Files\Common Files\VMware\Drivers\pvscsi\Win8\pvscsi.cat",4,N   None of these seem to get the drivers installed. Any ideas?   Thanks!
Hey LucD I have a question related to getting my script to handle disks with multiple partitions. I just want it to throw a warning if a vDisk has 2 or more volumes on it. So for example, $Result co... See more...
Hey LucD I have a question related to getting my script to handle disks with multiple partitions. I just want it to throw a warning if a vDisk has 2 or more volumes on it. So for example, $Result contains 5 objects from the Get-SCSIDisks function: ComputerName   : [Obfuscated] Disk           : \\.\PHYSICALDRIVE2 DriveLetter    : VolumeName     : [Obfuscated] Size           : 99 FreeSpace      : 99 DiskModel      : VMware Virtual disk SCSI Disk Device Partition      : Disk #2, Partition #0 SCSIBus        : 0 SCSITargetId   : 2 PSComputerName : [Obfuscated] ComputerName   : [Obfuscated] Disk           : \\.\PHYSICALDRIVE0 DriveLetter    : C: VolumeName     : Size           : 99 FreeSpace      : 65 DiskModel      : VMware Virtual disk SCSI Disk Device Partition      : Disk #0, Partition #1 SCSIBus        : 0 SCSITargetId   : 0 PSComputerName : [Obfuscated] ComputerName   : [Obfuscated] Disk           : \\.\PHYSICALDRIVE3 DriveLetter    : G: VolumeName     : [Obfuscated] Size           : 299 FreeSpace      : 193 DiskModel      : VMware Virtual disk SCSI Disk Device Partition      : Disk #3, Partition #0 SCSIBus        : 0 SCSITargetId   : 3 PSComputerName : [Obfuscated] ComputerName   : [Obfuscated] Disk           : \\.\PHYSICALDRIVE1 DriveLetter    : E: VolumeName     : New1 Size           : 19 FreeSpace      : 19 DiskModel      : VMware Virtual disk SCSI Disk Device Partition      : Disk #1, Partition #0 SCSIBus        : 0 SCSITargetId   : 1 PSComputerName : [Obfuscated] ComputerName   : [Obfuscated] Disk           : \\.\PHYSICALDRIVE1 DriveLetter    : F: VolumeName     : New2 Size           : 20 FreeSpace      : 20 DiskModel      : VMware Virtual disk SCSI Disk Device Partition      : Disk #1, Partition #1 SCSIBus        : 0 SCSITargetId   : 1 PSComputerName : [Obfuscated]     So volumes E: and F: exist on the same SCSIBus/SCSITargetID   I've been struggling with how to make this comparison. I think I need to combine the SCSIBus and SCSITargetID into one variable for each of the objects, then check those variables to see which are not unique.
I'm not sure; I have only tested it with single partition volumes. You have me curious now, but I'm assuming it would delete the whole disk of any partition that had a volume which matched the name. ... See more...
I'm not sure; I have only tested it with single partition volumes. You have me curious now, but I'm assuming it would delete the whole disk of any partition that had a volume which matched the name. I may test that out and write in some considerations for it.
I am currently working on a similar script. This what I've come up with for non-DRS clusters and migrations. I have tested the migration of VM's off of the selected host to other hosts in the cluster... See more...
I am currently working on a similar script. This what I've come up with for non-DRS clusters and migrations. I have tested the migration of VM's off of the selected host to other hosts in the cluster, and that seems to work. It isn't very smart (ie it doesn't take into account resource utilization or anything), but it does disperse the count of VM's relatively evenly across other hosts in the cluster. I have not yet tested the migration back to the original host portion yet. But my logic is that if the original array of VM's that was migrated off the host doesn't change, it should be able to reuse that array and migrate them all back to the host after patching. Also, if you'd like to see the rest of the script, I can share. The basic idea is to use a do/until loop to loop through an array of hosts in the cluster and patch them all one at a time, accommodating for single host clusters, DRS/non-DRS clusters, and a few more features as well.       $ClusterName = Read-Host "Please enter the full name of the cluster you want to update" $HostArray = Get-Cluster $ClusterName | Get-VMHost $HostCount = $HostArray.count $SelectHost = $HostArray $HostName = $SelectHost.name # Migrate powered on VM's off of current host Write-Host "Migrating VM's off of host $HostName to other hosts in cluster $ClusterName." -ForegroundColor Cyan -BackgroundColor Black "$(Get-Date) - Migrating VM's off of host $HostName to other hosts in cluster $ClusterName." >> $LogFile $VMArray = $SelectHost | Get-VM | where {$_.powerstate -eq ‘PoweredOn’ -and $_.name -notlike '*vCLS-*'} $VMCount = $VMArray.count $OtherHostsArray = $GetCluster | Get-VMHost | where {$_.name -notlike "$HostName"} $OtherHostsCount = $OtherHostsArray.count $VMInt = 0 $HostInt = 0 do { $TargetVM = $VMArray[$VMInt].name $TargetHost = $OtherHostsArray[$HostInt].name Write-Host "Migrating $TargetVM to $TargetHost" $VMArray[$VMInt] | Move-VM -Destination $OtherHostsArray[$HostInt] $VMInt++ $HostInt++ if ($HostInt -eq $OtherHostsCount){ $HostInt = 0 } else {} } until ($VMInt -eq $VMCount) # Confirm that all powered on VM's are migrated off of current host do { $VMArrayCount = ($SelectHost | Get-VM | where {$_.powerstate -eq ‘PoweredOn’ -and $_.name -notlike '*vCLS-*'}).count Write-Host "Confirming that all powered-on VM's are migrated off of $HostName..." -ForegroundColor Cyan -BackgroundColor Black "$(Get-Date) - Confirming that all powered-on VM's are migrated off of $HostName..." >> $LogFile Start-Sleep 5 } until ($VMArrayCount -eq "0") ################################### Perform ESXi update steps ################################### # Migrate powered on VM's back to current host Write-Host "Migrating VM's back to host $HostName." -ForegroundColor Cyan -BackgroundColor Black "$(Get-Date) - Migrating VM's back to host $HostName." >> $LogFile $VMArray | Move-VM -Destination $SelectHost            
I recently wrote a script which uses two functions I found online that can be modified to do what you want. My example matches a Windows volume name with the VM disk, and then deletes the VM disk. Se... See more...
I recently wrote a script which uses two functions I found online that can be modified to do what you want. My example matches a Windows volume name with the VM disk, and then deletes the VM disk. See below     <############################################################################################### ________ .__ __ ____ _________ ________ .__ __ \______ \ ____ | | _____/ |_ ____ \ \ / / \ \______ \ |__| _____| | __ | | \_/ __ \| | _/ __ \ __\/ __ \ \ Y / \ / \ | | \| |/ ___/ |/ / | ` \ ___/| |_\ ___/| | \ ___/ \ / Y \ | ` \ |\___ \| < /_______ /\___ >____/\___ >__| \___ > \___/\____|__ / /_______ /__/____ >__|_ \ \/ \/ \/ \/ \/ \/ \/ \/ ###############################################################################################> <# Script Name: Delete_VM_Disk Author: VMTN Communities: mk_ultra Reddit: /u/powershellnovice3 Version: # v1.0 - 2-8-23 Description: # Finds a Windows volume by name ($VolumeName), identifies the SCSI ID of the Windows volume, then deletes the corresponding VM disk Notes: # Change the 3 "$VolumeName" variables to delete the VM disk of a different volume name # Script is currently configured to run against the 999 server on a cluster #> # Create log file directory if it doesn't exist New-Item -Path "C:\scripts\logs" -ItemType "directory" -ErrorAction SilentlyContinue # Set variables $ScriptName = "Delete_VM_Disk.ps1" $Author = "mk_ultra" $Version = "1.0" $LastUpdated = "2-9-23" $LogFile = "C:\scripts\logs\Delete_VM_Disk.log" $Description = "-Finds a Windows volume by name, identifies the SCSI ID of the Windows disk, then deletes the corresponding VM disk" $VolumeName = "Data" # Import VMware modules Write-Host "Importing VMWare modules." -ForegroundColor Cyan -BackgroundColor Black Import-Module VMware.VumAutomation Import-Module VMware.VimAutomation.Core Import-Module VMware.VimAutomation.Storage Import-Module VMware.VimAutomation.Common Import-Module VMware.VimAutomation.License # Print script information Write-Host "`nScript Name: $ScriptName" -ForegroundColor Yellow Write-Host "Author: $Author" -ForegroundColor Yellow Write-Host "Version: $Version" -ForegroundColor Yellow Write-Host "Last Updated: $LastUpdated" -ForegroundColor Yellow Write-Host "Log File: $LogFile" -ForegroundColor Yellow Write-Host "Description: `n$Description" -ForegroundColor Yellow # Prompt for vCenter to connect to $vCenter = (Read-Host "`nEnter FQDN of vCenter to connect to") Connect-VIServer "$vCenter" try { # Show contents of input file, allow user to make changes until 'y' is input do { Write-Host "`nPlease confirm that the text file located at 'C:\scripts\input.txt' contains a full list of the cluster numbers you wish to target, one per line.`nCurrent list contents are displayed below:" -ForegroundColor Cyan -BackgroundColor Black Get-Content "C:\scripts\input.txt" $Answer = Read-Host "`nIf the above list is correct, enter 'y' to continue. Otherwise, update the file and press 'Enter' to show file contents again." } until ($Answer -eq "y") $InputFile = Get-Content "C:\scripts\input.txt" # Print script start time Write-Host "$(Get-Date) - $ScriptName started." -ForegroundColor Cyan -BackgroundColor Black "$(Get-Date) - $ScriptName started." >> $LogFile $StartTime = $(Get-Date) foreach ($I in $InputFile) { $ClusterName = "$I"+"_Cluster" $Server = Get-Cluster $ClusterName | Get-VM | Where {$_.Name -like "*999*"} # Check if cluster/server exists if ($Server) { # Obtain SCSI Bus and SCSI Target ID variables with two different PSSessions $Sesh1 = New-PSSession -computerName $Server $Result1 = Invoke-Command -Session $Sesh1 -Scriptblock { $ClusterName = $args[0] $Server = $args[0] $VolumeName = "Data" # Import Functions Function Get-ScsiDisks { <# .SYNOPSIS Retrieves disk details for VMWare Guests with corresponding SCSI disk details like SCSI ID and SCSI Bus. .DESCRIPTION Retrieves a concatenated object consisting of Win32_DiskDrive, Win32_LogicalDisk and Win32_DiskDriveToDiskPartition using WMI. For WinRM you can use Invoke-Command and inject the script. .PARAMETER ComputerName A single Computer or an array of computer names. The default is localhost ($env:COMPUTERNAME). .PARAMETER Credentials Commit Credentials for a different domain. .PARAMETER Verbose Run in Verbose Mode. .EXAMPLE PS C:> Get-ScsiDisks ComputerName Disk DriveLetter VolumeName Size FreeSpace DiskModel ------------ ---- ----------- ---------- ---- --------- --------- SERVER \.PHYSICALDRIVE1 Data 767 767 VMware Virtual di... SERVER \.PHYSICALDRIVE0 C: OS 59 39 VMware Virtual di... .EXAMPLE PS C:> Get-ScsiDisks | Out-GridView .EXAMPLE PS C:> Get-ScsiDisks | ft -a .EXAMPLE PS C:> Get-ScsiDisks -ComputerName (gc 'C:VMs.txt') -Credentials Get-Credential .LINK Home .NOTES Author: Sebastian Gräf Email: ps@graef.io Date: September 12, 2017 PSVer: 3.0/4.0/5.0 #> [Cmdletbinding()] Param ( [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)] $ComputerName = $Env:COMPUTERNAME, [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)] [ValidateNotNull()] [System.Management.Automation.PSCredential][System.Management.Automation.Credential()] $Credentials = [System.Management.Automation.PSCredential]::Empty ) Begin { Write-Verbose " [$($MyInvocation.InvocationName)] :: Start Process" $result=@() $ProgressCounter = 0 } Process { foreach ($Computer in $ComputerName) { $ProgressCounter++ Write-Progress -activity "Running on $Computer" -status "Please wait ..." -PercentComplete (($ProgressCounter / $ComputerName.length) * 100) if (Test-Connection $Computer -Count 1 -Quiet) { Write-Verbose " [$($MyInvocation.InvocationName)] :: Processing $Computer" try { Get-WmiObject -Class Win32_DiskDrive -ComputerName $Computer -Credential $Credentials | % { $disk = $_ $partitions = "ASSOCIATORS OF " + "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " + "WHERE AssocClass = Win32_DiskDriveToDiskPartition" Get-WmiObject -Query $partitions -ComputerName $Computer -Credential $Credentials | % { $partition = $_ $drives = "ASSOCIATORS OF " + "{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " + "WHERE AssocClass = Win32_LogicalDiskToPartition" Get-WmiObject -Query $drives -ComputerName $Computer -Credential $Credentials | % { $obj = New-Object -Type PSCustomObject -Property @{ ComputerName = $Computer Disk = $disk.DeviceID DiskSize = [math]::Truncate($disk.Size / 1GB); DiskModel = $disk.Model Partition = $partition.Name DriveLetter = $_.DeviceID VolumeName = $_.VolumeName Size = [math]::Truncate($_.Size / 1GB) FreeSpace = [math]::Truncate($_.FreeSpace / 1GB) SCSIBus = $disk.SCSIBus SCSITargetId = $disk.SCSITargetId } $result += $obj } } } } catch { Write-Verbose " Host [$Computer] Failed with Error: $($Error[0])" } } else { Write-Verbose " Host [$Computer] Failed Connectivity Test" } } $result | select ComputerName,Disk,DriveLetter,VolumeName,Size,FreeSpace,DiskModel,Partition,SCSIBus,SCSITargetId } End { Write-Progress -activity "Running on $Computer" -Status "Completed." -Completed Write-Verbose " [$($MyInvocation.InvocationName)] :: End Process" } } # Get SCSI ID of disk which has the volume name defined in the Variables section $VolumeDisk = Get-ScsiDisks | Where {$_.VolumeName -like "$VolumeName"} $SCSIBus = $VolumeDisk.SCSIBus $SCSIBus } Remove-PSSession $Sesh1 $Sesh2 = New-PSSession -computerName $Server $Result2 = Invoke-Command -Session $Sesh2 -Scriptblock { $ClusterName = $args[0] $Server = $args[0] $VolumeName = "Data" # Import Functions Function Get-ScsiDisks { <# .SYNOPSIS Retrieves disk details for VMWare Guests with corresponding SCSI disk details like SCSI ID and SCSI Bus. .DESCRIPTION Retrieves a concatenated object consisting of Win32_DiskDrive, Win32_LogicalDisk and Win32_DiskDriveToDiskPartition using WMI. For WinRM you can use Invoke-Command and inject the script. .PARAMETER ComputerName A single Computer or an array of computer names. The default is localhost ($env:COMPUTERNAME). .PARAMETER Credentials Commit Credentials for a different domain. .PARAMETER Verbose Run in Verbose Mode. .EXAMPLE PS C:> Get-ScsiDisks ComputerName Disk DriveLetter VolumeName Size FreeSpace DiskModel ------------ ---- ----------- ---------- ---- --------- --------- SERVER \.PHYSICALDRIVE1 Data 767 767 VMware Virtual di... SERVER \.PHYSICALDRIVE0 C: OS 59 39 VMware Virtual di... .EXAMPLE PS C:> Get-ScsiDisks | Out-GridView .EXAMPLE PS C:> Get-ScsiDisks | ft -a .EXAMPLE PS C:> Get-ScsiDisks -ComputerName (gc 'C:VMs.txt') -Credentials Get-Credential .LINK Home .NOTES Author: Sebastian Gräf Email: ps@graef.io Date: September 12, 2017 PSVer: 3.0/4.0/5.0 #> [Cmdletbinding()] Param ( [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)] $ComputerName = $Env:COMPUTERNAME, [Parameter(ValueFromPipelineByPropertyName = $true, ValueFromPipeline = $true)] [ValidateNotNull()] [System.Management.Automation.PSCredential][System.Management.Automation.Credential()] $Credentials = [System.Management.Automation.PSCredential]::Empty ) Begin { Write-Verbose " [$($MyInvocation.InvocationName)] :: Start Process" $result=@() $ProgressCounter = 0 } Process { foreach ($Computer in $ComputerName) { $ProgressCounter++ Write-Progress -activity "Running on $Computer" -status "Please wait ..." -PercentComplete (($ProgressCounter / $ComputerName.length) * 100) if (Test-Connection $Computer -Count 1 -Quiet) { Write-Verbose " [$($MyInvocation.InvocationName)] :: Processing $Computer" try { Get-WmiObject -Class Win32_DiskDrive -ComputerName $Computer -Credential $Credentials | % { $disk = $_ $partitions = "ASSOCIATORS OF " + "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " + "WHERE AssocClass = Win32_DiskDriveToDiskPartition" Get-WmiObject -Query $partitions -ComputerName $Computer -Credential $Credentials | % { $partition = $_ $drives = "ASSOCIATORS OF " + "{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " + "WHERE AssocClass = Win32_LogicalDiskToPartition" Get-WmiObject -Query $drives -ComputerName $Computer -Credential $Credentials | % { $obj = New-Object -Type PSCustomObject -Property @{ ComputerName = $Computer Disk = $disk.DeviceID DiskSize = [math]::Truncate($disk.Size / 1GB); DiskModel = $disk.Model Partition = $partition.Name DriveLetter = $_.DeviceID VolumeName = $_.VolumeName Size = [math]::Truncate($_.Size / 1GB) FreeSpace = [math]::Truncate($_.FreeSpace / 1GB) SCSIBus = $disk.SCSIBus SCSITargetId = $disk.SCSITargetId } $result += $obj } } } } catch { Write-Verbose " Host [$Computer] Failed with Error: $($Error[0])" } } else { Write-Verbose " Host [$Computer] Failed Connectivity Test" } } $result | select ComputerName,Disk,DriveLetter,VolumeName,Size,FreeSpace,DiskModel,Partition,SCSIBus,SCSITargetId } End { Write-Progress -activity "Running on $Computer" -Status "Completed." -Completed Write-Verbose " [$($MyInvocation.InvocationName)] :: End Process" } } # Get SCSI ID of disk which has the volume name defined in the Variables section $VolumeDisk = Get-ScsiDisks | Where {$_.VolumeName -like "$VolumeName"} $SCSITargetID = $VolumeDisk.SCSITargetID $SCSITargetID } Remove-PSSession $Sesh2 # Retrieve VM disk properties $VMView = Get-View -ViewType VirtualMachine -Filter @{'Name' = "$Server"} $VMDisks = ForEach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI Controller"})) { ForEach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | Where {$_.ControllerKey -eq $VirtualSCSIController.Key})) { [pscustomobject]@{ VM = $VM.Name HostName = $VMView.Guest.HostName PowerState = $VM.PowerState DiskFile = $VirtualDiskDevice.Backing.FileName DiskName = $VirtualDiskDevice.DeviceInfo.Label DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB SCSIController = $VirtualSCSIController.BusNumber SCSITarget = $VirtualDiskDevice.UnitNumber DeviceID = $null } } } # Match VM disk with SCSI ID that matches Windows disk SCSI ID $MatchingDisk = $VMDisks | where {$_.SCSIController -like "$Result1" -and $_.SCSITarget -like "$Result2"} # Select the VM disk object $GetVMDiskMatch = Get-HardDisk -VM $Server | where {$_.Name -like $MatchingDisk.DiskName} # Check for multiple matches, or no matches if ($GetVMDiskMatch.count -eq 1){ # Example write to log file Write-Host "Deleting the VM disk for a Windows volume named $VolumeName on $Server." -ForegroundColor Green -BackgroundColor Black "$(Get-Date) - Deleting the VM disk for a Windows volume named $VolumeName on $Server." >> $LogFile # Delete the VM disk Remove-HardDisk $GetVMDiskMatch -DeletePermanently -Confirm:$false } else { Write-Host "No single VM disk match was found for a Windows volume named $VolumeName on $Server." -ForegroundColor Red -BackgroundColor Black "$(Get-Date) - No single VM disk match was found for a Windows volume named $VolumeName on $Server." >> $LogFile } } else { Write-Host "No 370 server found for $ClusterName." -ForegroundColor Red -BackgroundColor Black "$(Get-Date) - No 370 server found for $ClusterName." >> $LogFile } } } catch { $_ } # Print script end time $ElapsedTime = $(Get-Date) - $StartTime $TotalTime = "{0:HH:mm:ss}" -f ([datetime]$ElapsedTime.Ticks) Write-Host "$(Get-Date) - $ScriptName completed. Total script run time: $TotalTime`nLog file located at $LogFile" -ForegroundColor Cyan -BackgroundColor Black "$(Get-Date) - $ScriptName completed. Total script run time: $TotalTime" >> $LogFile  
This is indeed the answer. How can I tell that it's an array when it only outputs 1 item?
Hello, I am trying to dynamically set a host's DNS server to the local domain controller in the cluster. It sounds like this may just be an object type error? It works when I set the $DNSServer vari... See more...
Hello, I am trying to dynamically set a host's DNS server to the local domain controller in the cluster. It sounds like this may just be an object type error? It works when I set the $DNSServer variables to a "[ip address]". What is the difference between a String[] and a System.String[] ?   $DomainController = Get-Cluster $ClusterName | Get-VM | Where-Object {$_.Name -like "*999"} $DomainControllerIP = $DomainController.Guest.IPAddress $DNSServer1 = $DomainControllerIP $DNSServer2 = "[redacted]"   $VMHostNetwork = Get-VMHostNetwork -Host $IPAddress Set-VMHostNetwork -Network $VMHostNetwork -DomainName $SearchDomain -SearchDomain $SearchDomain -HostName $HostName -DNSAddress $DNSServer1, $DNSServer2 -DnsFromDhcp:$false   Full error: Set-VMHostNetwork : 5/15/2023 8:29:43 AM Set-VMHostNetwork Invalid value in DNS parameter: "System.String[]" + ... Set-VMHostNetwork -Network $VMHostNetwork -DomainName $Se ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Set-VMHostNetwork], InvalidArgument + FullyQualifiedErrorId : Core_SetVmHostNetwork_TryValidateParameterList_InvalidDNSName,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostNetwork
Perfect! Thank you!
What should be a simple one liner is driving me insane. I am trying to rename a datastore on a new host via PowerCLI. $IPAddress = [host IP address] $HostName = [host name] $ESXiHost = Get-VM... See more...
What should be a simple one liner is driving me insane. I am trying to rename a datastore on a new host via PowerCLI. $IPAddress = [host IP address] $HostName = [host name] $ESXiHost = Get-VMHost $IPAddress $DefaultDatastoreName = ($ESXiHost | Get-Datastore | where {$_.capacityGB -like "*95*"}).Name $NewOSDatastoreName = $HostName+"_os" $ESXIHost | Get-Datastore -Name $DefaultDatastoreName | Set-Datastore -Name $NewOSDatastoreName -Confirm:$False   I have confirmed each of these individual variables yields the correct object/string. I have tried eliminating variables by feeding in explicit strings. No matter what I do, whenever I run the final line, it just returns the current datastore name:   Name FreeSpaceGB CapacityGB ---- ----------- ---------- temp_name 93.844 95.250   Please help!