Hi,
I was creating a New-PSDrive to use the Copy-Datastore function in the following way:
$vcServer = Connect-VIServer -Server: -Destination MyDS:\Installer\ -Force
This was working fine for me yesterday but seems to be giving a problem today and I just cant figure why. PLease help. Error listed below
New-PSDrive : Cannot bind parameter 'Datastore' to the target. Exception settin
g "Datastore": "Invalid location type. Location accepts only VIDatastore object
s."
At C:\DOCUME1\lahird\LOCALS1\Temp\7d6a8a2f-c779-4253-a09e-7fcca9341784.ps1:2
char:68
+ New-PSDrive -Name MyDS1 -PSProvider VimDatastore -Root \ -Datastore <<<< "da
tastore2"
+ CategoryInfo : WriteError: ( , ParameterBindingE
xception
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Comm
ands.NewPSDriveCommand
I can reproduce the exact same error when I place a $null value in the $desiredDataStore variable
Can you check if
Get-Datastore <name>
returns a valid DatastoreImpl object ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I can reproduce the exact same error when I place a $null value in the $desiredDataStore variable
Can you check if
Get-Datastore <name>
returns a valid DatastoreImpl object ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You hit it on the head Luc
That was the problem
Hi,
I am getting the same error and when I try what LucD recommended - I get the datastore information as expected - I guess:
[vSphere PowerCLI] D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> get-datastore -name master_images
Name FreeSpaceMB CapacityMB
---- ----------- ----------
Master_Images 45407 45407
Master_Images 45406 45407
Pls note that Master_Images is an NFS datastore - can that be the cause of the following error:
[vSphere PowerCLI] D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> New-PSDrive -Name
dest -PSProvider ViMdatastore -Root '\' -location $ds2
New-PSDrive : Cannot bind parameter 'Datastore' to the target. Exception setting "Datastore": "Invalid location type. Location accepts only VIDatastore objects."
At line:1 char:68
+ New-PSDrive -Name dest -PSProvider ViMdatastore -Root '\' -location <<<< $ds2
+ CategoryInfo : WriteError: (:) [New-PSDrive], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewPSDriveCommand
Pls help - thanks.
-sf
Looks like you have more than one Master_Images datastore which would be passing an array rather than a VIDatastore object.
I am connecting PSdrive to NFS without problem for the record. I am having trouble with Get-ChildItem -Exclude however but that's another issue.
Are you looking to have a PSdrive map to each of the two datastores? You could do the following or create a loop. Depends on what you're usage case is.
$ds = Get-Datastore Master_Images
$psdrive1 = New-PSDrive -Name "dest1" -PSProvider ViMdatastore -Root \ -location $ds[0]
$psdrive2 = New-PSDrive -Name "dest2" -PSProvider VimDatastore -Root \ -location $ds[1]
Doing a loop is a little more challenging since you would need to adjust the name dynamically.
$ds = Get-Datastore Master_Images
$i = 0
foreach ($drive in $ds) {
$name = $drive.Name + $i
New-PSDrive -Name $name -PSProvider ViMdatastore -Root \ -location $drive
$i = $i + 1
}
You'll just need to recall that you're adding a digit at the end of the drive name.
Thanks for the reply Josh.
What I am trying to do is create a script which can copy the contents of a folder to another folder (NFS) on a weekly schedule basis. The first is a full copy and all subsequent should be delta copies. The NFS share is also mounted to another vCenter in another datacenter.
I removed the second mount but still get the same error.
Thx,
-sf
Hi Sf,
I had the same error and apparently I had connected to the same vcenter twice and my
$ Datastore = Get-Datastore –Name DatastoreABCD was returning two objects. I gave a select-unique option and it worked .
$ Datastore = Get-Datastore –Name DatastoreABCD | select unique
Apparently, I have changed the default $DefaultVIServers to just one entry ie my vc and seems like it has fixed it. hope this helps.