Looking for a PowerCLI script to collect the below information and having it output to file.
1. All virtual machines running on each individual ESXi Host
2. If moved (vmotioned) to another host in the last 90 days flag/report on each vm individually – What vm moved where and when
3. # of times each individual virtual machine moved in the last 90 days
vSphere versions 5.0, 5.5, and 6.0
Kindly help me how i can achieve this. LucD
Chetan
This script works as accepted, but we need to update this script with few changes:
- Connect and disconnect from vCenter (We can call the Connect and Disconnect sever cmdlet)
- Allow parameters for vCenter name, vCluster name, and prompt for credentials as needed
- Remove the following output User ID
- How we can ensure the script loads any PowerCLI modules it needs automatically
Please do let me know on this.
Did you already try the script in Get the vMotion/svMotion history ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script works as accepted, but we need to update this script with few changes:
- Connect and disconnect from vCenter (We can call the Connect and Disconnect sever cmdlet)
- Allow parameters for vCenter name, vCluster name, and prompt for credentials as needed
- Remove the following output User ID
- How we can ensure the script loads any PowerCLI modules it needs automatically
Please do let me know on this.
The functionality is implemented as 2 functions, so you could call the Get-MotionHistory function in a loop.
In that loop you can do the Connect- and Disconnect-VIServer respectively before and after the call the function.
The Get-MotionHistory function returns objects, so you can use a Select-Object on the returned objects, and select whatever properties you want.
On the loading of PowerCLI, that depends on which PowerCLI version you are using.
If you're using the current latest version (6.3), you can use something like the following lines
$loaded = Get-Module -Name VMware* -ErrorAction SilentlyContinue | where{$_.Name -notmatch 'Common$|SDK$'} | Select Name
Get-Module -Name VMware* -ListAvailable | where{$loaded -notcontains $_.Name} | %{Import-Module -Name $_.Name}
$loadedSnap = Get-PSSnapin -Name VMware* -ErrorAction SilentlyContinue | where{$_.Name -notmatch 'Core$'} | Select Name
Get-PSSnapin -Name VMware* -Registered | where{$loadedSnap -notcontains $_.Name} | %{Add-PSSnapin -Name $_.Name}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you
Now I have one issue while exporting the .csv file to temp location or any other location (such as c:\test.csv) where I see an error : Access to the path 'C:\Test.csv' is denied.
As this are the location where system always look for Administrator Permissions we can copy past or create new files to this location via GUI but using PowerCLI Export-Csv cmdlet it does not allow us to create a new file.
Can you please help me to export a .csv file allowing permissions to such locations.
You are probably trying to overwrite a CSV file that has the read-only attribute.
Add the -Force switch to the Export-Csv cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for your help now all works fine for me.
You are LucD genius in powerCLI.