Hi,
Can some one help me on the PowerCLI script to have below details, this is like I will give the servers list and it has to fetch the below details with respective to the VM's. Output in .CSV would be very fine.
The VM's Name should be
$vms.VMName = $vm.Name
What other columns have the wrong values according to you?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Its not wrong value, I have just changed the dummy values to post it in the public forum.
Let me try with changing that as you suggested.
Getting below error..
Get-Datacenter : Cannot bind parameter 'VM'. Cannot convert the "VMware.Vim.VirtualMachine" value of type
"VMware.Vim.VirtualMachine" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine".
At T:\Script\Checks\PreCheckScript.ps1:35 char:43
+ $vms.Datacenter = (Get-Datacenter -VM $vm).Name
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Datacenter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatacente
r
Get-Datacenter : Cannot bind parameter 'VM'. Cannot convert the "VMware.Vim.VirtualMachine" value of type
"VMware.Vim.VirtualMachine" to type "VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine".
At T:\Script\Checks\PreCheckScript.ps1:35 char:43
+ $vms.Datacenter = (Get-Datacenter -VM $vm).Name
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Datacenter], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatacente
r
That is not the code I provided.
$vms.Datacenter = (Get-Datacenter -VM $vm.Name).Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There was copy past mistake thats why missed to make in changes in script. Now, I have just ran through your codes only.
Apart from black area, I am not getting other values.
Also, Complaint and multiwriter values getting for 1 vm but not for others. Really I wonder, what is causing this.
I think, I am stressing you and very sorry for it.
All those properties were in my original reply.
You removed them, so I assumed you didn't want them.
It's just a matter of copying the lines from my original reply into the latest version.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are really great...! All works fine and need one last and final changes..
When I am having VM's with multiple networks , am getting values like below. Can you help me to add block to get all network details in NIC wise if VM is having multiple network.
Also, please add one more block to check if VM is part of any DRS rule
To get multiple portgroups change that line to
$vms.Portgroup = if ($vm.Network) { (Get-View -Id $vm.Network -Property Name | Select-Object -ExpandProperty Name) -join '|' }
Not sure what exactly you want to see for DRS rule.
There are many types of DRS rules: affinity, anti-affinity, VM-to-VMHost. To report this in one column is quite tricky.
Have a look at Re: Need a script to pull the DRS rules, Vms on the rule, and if the rule is disabled then need an ... to see what I mean.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I understand. We cannot get DRS rule config in single column on VM basis.
So far ...so good script work, this would be enough for now.
Thanks a looooooooooot for yourinstant help.. I would say again.. You are really great scripting in PowerCLI..
Hi LuCD,
One small doubt, I was trying to get the ourput CSV with current date as below, but not getting value.
Is here anything I am missing in method of calling variable?
$Date = Get-Date
$Report | Export-CSV -Path 'T:\Report_$Date.csv' -NoTypeInformation -UseCulture
You have to use double quotes if you want variable substitution.
$Report | Export-CSV -Path "T:\Report_$Date.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Still I am getting below error.
Export-CSV : The given path's format is not supported.
At T:\Script.ps1:99 char:21
+ $Report | Export-CSV -Path "T:\Report_$Date.csv"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Export-Csv], NotSupportedException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand
That most probably because the resulting filename contains some blanks or slashes or other invalid characters for a file path.
Try specifying what kind of text appears in the filename.
For example
$Report | Export-CSV -Path "T:\Report_$Date.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes it works, now..
Great.. ! Thanks ..