HI Luc,
Good morning
could you suggest the way to find all configurations files .vmx from datastore .
we are doing this to find whats vms needs to be added to inventory in case they were removed earlier .
i tried to find in following way
$datastores = ("SAN01","SAN_02","SAN_03","SAN_D4","TRDL_VSAN1","VSAN2")
$report=foreach ($d in $datastores)
{
get-vm -datastore $d|select name
}
$report|out-file vmnames.txt
however above will give information depending on the display name of vcenter .what needs to be modified to get .vmx files in datastore.
You can search for all unregistered VMX file with something like this
$Datastores = 'DS1','DS2'
foreach($Datastore in Get-Datastore $Datastores) {
# Collect .vmx paths of registered VMs on the datastore
$registered = @{}
Get-VM -Datastore $Datastore | %{$registered.Add($_.ExtensionData.Summary.Config.VmPathName.Split('/')[-1],$true)}
# Set up Search for .VMX Files in Datastore
New-PSDrive -Name TgtDS -Location $Datastore -PSProvider VimDatastore -Root '\' | Out-Null
$unregistered = @(Get-ChildItem -Path TgtDS: -Filter *.vmx -Recurse |
where {$_.FolderPath -notmatch ".snapshot" -and !$registered.ContainsKey($_.Name)})
Remove-PSDrive -Name TgtDS
}
$unregistered | Select Name,FolderPath
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thnaks iam checking this.
could you explain the above code specially new-psdrive part .
it seems it does not give the desired output .$unregistered giving me vms which are registered .
For the PSDrive part, see about_vimdatastore
Are you sure that the VMs that you say are registered, are also registered on the datastore that is reported?
There can be vmx files on other datastores than the one on which the VM is registered
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
its giving blank output now .for sure there is one unregistered vm in one of the datastores . its name is"test"
as mentioned below.
also to avoid confusion i have included all datastores in $datastore array.
Try the updated version above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok but i dont see any updated version from your side .
I updated the script I gave earlier in place.
See above
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sorry that also did not work.
Strange, works for me.
Can we do some debugging.
What does this return for that datastore?
$dsName = 'Your-DS-Name'
$ds = Get-Datastore -Name $dsName
Get-VM -Datastore $ds | select Name,@{N='VMX';E={$_.ExtensionData.Summary.Config.VmPathName.Split('/')[-1]}}
New-PSDrive -Name TgtDS -Location $ds -PSProvider VimDatastore -Root '\' | Out-Null
Get-ChildItem -Path TgtDS: -Filter *.vmx -Recurse
Remove-PSDrive -Name TgtDS
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
so Get-ChildItem -Path TgtDS: -Filter *.vmx -Recurse gave test.vmx also which is not given by the $unregistered in updated script.
Did you do the previous run with more than 1 datastore?
Is there another test VM on another datastore?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes previous run with 4 datastores and we used foreach loop.
No,there is only one unregistered test vm in first datastore which was displayed earlier .
Then I can't explain why it doesn't work for you.
The debug run earlier showed all the correct values as I expected them.
Did another test in my environment, and it works.
Unless something went wrong in your copy/paste.
Can you attach the script as you are running it?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
iam going to check this again .
also can yu suggest if there is a way to find duplicate session of powercli running under my credential.
as many times the same script(it happens with this script also and other previous script)gives me different output which is weird but true .
and i have been forced to think that a duplication session from somewhere else is running under my credential .
could you suggest any thing on above/
Try like this (but this will only work if you logon with an AD account, not with a SSO account.
Get-View SessionManager |
select -ExpandProperty SessionList |
where{$_.UserName -match "$($env:USERNAME)"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks luc .i will be checking both shortly.
i got following .and iam running this session from 141.11.101.89 also i see same output again from 127.0.0.1 .is this normal output.???
also iam not sure what is callcount.
That seems to be the Web Client you have open..
I see the same, no idea why this shows the localhost.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference