wetnose88's Posts

If the date format is in MM/dd/yyyy h:mm:ss AM/PM, the sort result is not correct. I have been working on report storage events from multiple arrays, the event creation time is MM/dd/yyyy h:mm:ss AM... See more...
If the date format is in MM/dd/yyyy h:mm:ss AM/PM, the sort result is not correct. I have been working on report storage events from multiple arrays, the event creation time is MM/dd/yyyy h:mm:ss AM/PM, I need to  convert the datetime to DateTime objects, then do the sort, after the sort, convert the output back again for us to understand. The code to sort date and time I used is as follows, hopefully this can help. # Convert the data in the specified column to DateTime objects $dateColumn = $dataRange.Columns.Item("F") foreach ($cell in $dateColumn.Cells) { $cell.Value2 = [DateTime]::Parse($cell.Text) } # Perform the sort on the data range (descending order) $dataRange.Sort($dateColumn, 2) # Use 2 for descending order # Convert the sorted date and time values back to their original format foreach ($cell in $dateColumn.Cells) { $cell.NumberFormat = "MM/dd/yyyy h:mm:ss AM/PM" } # Autofit all columns in the worksheet $usedRange.Columns.AutoFit()    
This is very interesting, just to my curiosity, where does the UPPERCASE naa number come from? If I remember correctly, I haven't never seen UPPERCASE naa number in storage device Identifier.
    I changed your code slightly by Sort-Object VM instead of Sort-Object @{E={$_.Parent.Name}}, please try and see if make a difference. Get-VM | Get-NetworkAdapter | Select-Object @{N="VM";E={$_... See more...
    I changed your code slightly by Sort-Object VM instead of Sort-Object @{E={$_.Parent.Name}}, please try and see if make a difference. Get-VM | Get-NetworkAdapter | Select-Object @{N="VM";E={$_.Parent.Name}}, name, NetworkName, type, MacAddress, @{N="Connection State";E={Set-Color -string $_.ConnectionState}} | Sort-Object VM | ConvertTo-Html |% { ($_.Replace("&lt;","<")).Replace("&gt;",">").replace("&quot;",'"').replace("&#39;",'"') } | Out-String    
Thanks a lot for your quick response and helps, tested working without errors now!
Hi Luc, The script worked, but get some error, it rename two of the LUNs in my csv successfully to $newname Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empt... See more...
Hi Luc, The script worked, but get some error, it rename two of the LUNs in my csv successfully to $newname Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:4 char:21 + $storSys = Get-View $esx.ConfigManager.StorageSystem + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Hi LucD, Can you please remove the real ESXi host name in you reply, I noticed that and changed it already to $esx = "mytest.com" Thanks
Before I open this new one, I have referenced the following posts in the past https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/how-to-change-quot-display-name-quot-via-PowerCLI-command/... See more...
Before I open this new one, I have referenced the following posts in the past https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/how-to-change-quot-display-name-quot-via-PowerCLI-command/m-p/2625493#M89257 https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Powercli-script-to-update-SCSI-LUN-DisplayName/m-p/2148916#M70016 https://www.eehelp.com/question/powercli-script-to-update-scsi-lun-displayname/ https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Update-SCSI-LUN-DisplayName/td-p/2089586 https://communities.vmware.com/t5/vSphere-Storage-Discussions/Change-Device-Display-Name/m-p/802158#1578617
uuid,DisplayName naa.60000970000120001295533030303031,PowerMax_odd_system_device naa.60000970000120001297533030303031,PowerMax_even_system_device $csv = import-csv "$env:USERPROFILE\Input\testrename... See more...
uuid,DisplayName naa.60000970000120001295533030303031,PowerMax_odd_system_device naa.60000970000120001297533030303031,PowerMax_even_system_device $csv = import-csv "$env:USERPROFILE\Input\testrename.csv" $esx = "mytest.com" $storSys = Get-View $esx.ConfigManager.StorageSystem Foreach ($item in $csv){ $uuid = $item.uuid $newname = $item.DisplayName Get-ScsiLun -VMHost $esx -LUNType disk -CanonicalName $uuid | %{ $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid,$newname) } } Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:4 char:21 + $storSys = Get-View $esx.ConfigManager.StorageSystem + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Tried to move some of the vms use set-harddisk, get following warning messages: WARNING: Parameter 'Datastore' is obsolete. 'Datastore' parameter is obsolete. To move hard disk to another datastore ... See more...
Tried to move some of the vms use set-harddisk, get following warning messages: WARNING: Parameter 'Datastore' is obsolete. 'Datastore' parameter is obsolete. To move hard disk to another datastore and change it's storage format, use 'Move-HardDisk' cmdlet instead. What if: Performing the operation "Setting Datastore: mytestlab_03." on target "Hard disk 1". WARNING: Parameter 'Datastore' is obsolete. 'Datastore' parameter is obsolete. To move hard disk to another datastore and change it's storage format, use 'Move-HardDisk' cmdlet instead. What if: Performing the operation "Setting Datastore: mytestlab_03." on target "Hard disk 2".    
My code to process multiple vCenters are as follows: $vcenters = "mytest01.homelab.ca","mytest02.homelab.ca","mytest03.homelab.ca","mytest04.homelab.ca" $creds = import-clixml -Path "C:\Docs\Scripts... See more...
My code to process multiple vCenters are as follows: $vcenters = "mytest01.homelab.ca","mytest02.homelab.ca","mytest03.homelab.ca","mytest04.homelab.ca" $creds = import-clixml -Path "C:\Docs\Scripts\Credentials\Cred_jzadmin.xml" $outputfile = "$env:USERPROFILE\Outputs\VmOsDriveFreeSpace\VMDiskSystemDriveFreeSpace_$(get-date -Format yyyy-MM-dd-HH).xlsx" $stopwatch = New-Object System.Diagnostics.Stopwatch $stopwatch.Start() Foreach ($vcenter in $vcenters){ $report = @() Write-Host "Connectint to $vCenter ......" -ForegroundColor Cyan Connect-VIServer -Server $vcenter -Credential $Creds ...... Write-Host "Disconnect from $vCenter " -ForegroundColor Yellow Disconnect-viserver * -confirm:$false $report | Export-Excel "$outputfile " -WorkSheetname "$($vcenter)" } $stopwatch.Stop() $stopWatch write-host "Done!" Write-Host "Please review the reports under $outputfile" invoke-item $outputfile
I created my owned scripts and tested working based on the post from LucD, hope this can help you as well. https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/How-to-set-hotadd-memory-or-cp... See more...
I created my owned scripts and tested working based on the post from LucD, hope this can help you as well. https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/How-to-set-hotadd-memory-or-cpu-using-Powercli-in-Vsphere-6-7/td-p/2270295 # connect to selected vCenter Connect-VIServer -Server $vcenter -User $creds.User -Password $creds.Password write-host "Connecting to vCenter server $vcenter" -ForegroundColor Green $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.CpuHotAddEnabled = $true $spec.MemoryHotAddEnabled = $true $VMs = gc C:\Docs\scripts\input\torappwfmqv.txt foreach($vmName in $VMs){ #Shutdown VM Guest and VM $vm = Get-VM -Name $vmName Write-Host "Initiating Guest Shutdown for VM + $VM" -ForegroundColor Red if($vm.Guest.State -eq "Running"){ Shutdown-VMGuest -VM $vm -Confirm:$false } else{ Stop-VM -VM $vm -Confirm:$false } #Wait for VM to power off before executing config cmd section – in which case the config cmd will fail while((Get-VM $vm).PowerState -ne 'PoweredOff') { Start-Sleep -Seconds 10 } #Enable the CPU & Memory hotplug if(-not $vm.ExtensionData.Config.cpuHotAddEnabled -or -not $vm.ExtensionData.Config.memoryHotAddEnabled){ $vm.ExtensionData.ReconfigVM($spec) ) } #Power on VM after the change Write-Host "$VM is starting" -ForegroundColor Cyan Get-VM $vm | where {$_.status -eq "powered off"} Start-VM $vm -Confirm:$false } Write-Host Write-Host "Done" -ForegroundColor Green # Disconnect from vCenter Write-Host "Disconnect from vCenter $vcenter " -ForegroundColor Green disconnect-viserver -Server $vcenter -confirm:$false
Hi  I am using PowerCLI 12.7.0 build 20091289 over Windows PowerShell 5.1 BTW, since my current employer does not use SRM anymore, I can't tested it. PowerCLI Version ---------------- VMware.Pow... See more...
Hi  I am using PowerCLI 12.7.0 build 20091289 over Windows PowerShell 5.1 BTW, since my current employer does not use SRM anymore, I can't tested it. PowerCLI Version ---------------- VMware.PowerCLI 12.7.0 build 20091289 --------------- Component Versions --------------- VMware Common PowerCLI Component 12.7 build 20067789 VMware Cis Core PowerCLI Component PowerCLI Component 12.6 build 19601368 VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.7 build 20091293 $PSversiontable Name Value ---- ----- PSVersion 5.1.19041.3031 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.3031 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1  
Try the following, replace "Your vCenter server" with yours # Connect to protected site VC & SRM $creds = Get-Credential $vca = Connect-VIServer "Your vCenter server" -Credential $creds $srma = C... See more...
Try the following, replace "Your vCenter server" with yours # Connect to protected site VC & SRM $creds = Get-Credential $vca = Connect-VIServer "Your vCenter server" -Credential $creds $srma = Connect-SrmServer -Server $vca -Credential $creds -RemoteCredential $creds # Output Current SRM Configuration Report Get-SrmConfigReport
Hi there, Have you downloaded both SrmFunctions.ps1 and ReportConfiguration.ps1? Please download both and try to Dot-sourcing again. I tested on my laptop, done successfully. import-module "C:\docs... See more...
Hi there, Have you downloaded both SrmFunctions.ps1 and ReportConfiguration.ps1? Please download both and try to Dot-sourcing again. I tested on my laptop, done successfully. import-module "C:\docs\Scripts\Function\SrmFunctions.ps1" -verbose -Force import-module "C:\docs\Scripts\Function\ReportConfiguration.ps1" -verbose -Force VERBOSE: Loading module from path 'C:\docs\Scripts\Function\SrmFunctions.ps1'. VERBOSE: Dot-sourcing the script file 'C:\docs\Scripts\Function\SrmFunctions.ps1'. VERBOSE: Loading module from path 'C:\docs\Scripts\Function\ReportConfiguration.ps1'. VERBOSE: Dot-sourcing the script file 'C:\docs\Scripts\Function\ReportConfiguration.ps1'.
Good to know it is working for you as well!
# Load the custom functions . ./SrmFunctions.ps1 . ./Examples/ReportConfiguration.ps1 # Connect to protected site VC & SRM $creds = Get-Credential $vca = Connect-VIServer vc-w12-01a.corp.local -Cred... See more...
# Load the custom functions . ./SrmFunctions.ps1 . ./Examples/ReportConfiguration.ps1 # Connect to protected site VC & SRM $creds = Get-Credential $vca = Connect-VIServer vc-w12-01a.corp.local -Credential $creds $srma = Connect-SrmServer -Server $vca -Credential $creds -RemoteCredential $creds # Output Current SRM Configuration Report Get-SrmConfigReport # get recovery plan $rp = Get-RecoveryPlan "Anaheim" # get protected VM $pvm = $rp | Get-ProtectedVM | Select -First 1 # view recovery settings $rs = $pvm | Get-RecoverySettings -RecoveryPlan $rp # update recovery priority $rs.RecoveryPriority = "highest" # create new command callout $srmCmd = New-SrmCommand -Command '/bin/bash /root/failover.sh' -Description 'Run standard linux failover script' -RunInRecoveredVm # add command as post recovery command callout Add-PostRecoverySrmCommand -RecoverySettings $rs -SrmCommand $srmCmd # update the recovery settings on the SRM server Set-RecoverySettings -ProtectedVm $pvm -RecoveryPlan $rp -RecoverySettings $rs # validate recovery settings (view in report) Get-SrmConfigReportProtectedVm
Got your message, in order to change the  setting the priority (Highest, High, Normal Low and Lowest) for VMs in a particular Recovery Group in SRM, you can try following approach.(As the current com... See more...
Got your message, in order to change the  setting the priority (Highest, High, Normal Low and Lowest) for VMs in a particular Recovery Group in SRM, you can try following approach.(As the current company I am working do not use SRM, I can't do a test) Download the  custom SRM functions  https://raw.githubusercontent.com/benmeadowcroft/SRM-Cmdlets/99d036842c05738756afb26c11bc7ef5a4a524f8/SrmFunctions.ps1 https://github.com/benmeadowcroft/SRM-Cmdlets/blob/99d036842c05738756afb26c11bc7ef5a4a524f8/Examples/ReportConfiguration.ps1      
I tested the script in my environment, following are the exported result, I have thousands of VMs, just part of the result. VM Name Power State Interface ConnectionState Type Connect on Boot... See more...
I tested the script in my environment, following are the exported result, I have thousands of VMs, just part of the result. VM Name Power State Interface ConnectionState Type Connect on Boot Operating System OS Family VM001 PoweredOn Network adapter 1 Connected e1000 TRUE Red Hat Enterprise Linux 5 (64-bit) linuxGuest VM002 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Red Hat Enterprise Linux 7 (64-bit) linuxGuest VM003 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Red Hat Enterprise Linux 6 (64-bit) linuxGuest VM004 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE CentOS 7 (64-bit) linuxGuest VM005 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2012 (64-bit) windowsGuest VM006 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Red Hat Enterprise Linux 7 (64-bit) linuxGuest VM007 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2012 (64-bit) windowsGuest VM008 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2016 or later (64-bit) windowsGuest VM009 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2016 or later (64-bit) windowsGuest VM010 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Red Hat Enterprise Linux 8 (64-bit) linuxGuest VM011 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2012 (64-bit) windowsGuest VM012 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2012 (64-bit) windowsGuest VM013 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2016 or later (64-bit) windowsGuest VM014 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2016 or later (64-bit) windowsGuest VM015 PoweredOn Network adapter 1 Connected Vmxnet3 TRUE Microsoft Windows Server 2012 (64-bit) windowsGuest
Get-VM | Sort-Object -Property Name -PipelineVariable vm | ForEach-Object -Process { Get-NetworkAdapter -VM $vm | Where-Object { $_.ConnectionState.StartConnected -eq $true} | Select-Object @{N... See more...
Get-VM | Sort-Object -Property Name -PipelineVariable vm | ForEach-Object -Process { Get-NetworkAdapter -VM $vm | Where-Object { $_.ConnectionState.StartConnected -eq $true} | Select-Object @{N = "VM Name"; E = {$vm.Name }}, @{N = "Power State"; E = { $vm.PowerState } }, @{N = "Interface"; E = {$_.Name }}, @{N = 'ConnectionState'; E={if($_.ConnectionState.Connected){'Connected'}else{'NotConnected'}}}, @{N = "Type"; E = {$_.Type }}, @{N = "Connect on Boot"; E = {$_.ConnectionState.StartConnected}}, #@{N = "OS Full Name"; E = {$_.ExtensionData.Guest.guestFullName}}, @{N="Operating System"; E={@($vm.guest.OSFullName)}}, #@{N= "OS Family"; E = {{$_.ExtensionData.Guest.guestFamily}} @{N="OS Family"; E={@($vm.guest.guestFamily)}} }| Export-CSV $outputFile -NoTypeInformation -Append