I am writing this short blog after a long time. While explaining in-out of PowerShell to some of my friends in person, I discussed about PSProviders. Most of the knowledge about PSProvider is information only and as a script writer we dont really bother about how powershell is playing with different resources (Variable/function/Filesystem/Registery Keys etc) which are used in PowerShell Session or a Script.
However as a VMware Admin I do use PSProvider in background alot in order to move the datastore item from,
- datastore to datastore
- Datastore to local drive (Windows Drive or Shared Drive) or vice versa
In this Post we will learn about Copy-DatastoreItem cmdlet and PSProviders.
What is PSProvider?
In Simple Term, PSProviders are special repository(data stored within Powershell) to process the data as it recieves during PowerShell execution. This data is presented in their respective PowerShell drives which are known as PSDrive.
For Ex. See the below command output from Get-PSProvider
by default, you get above psproviders which are registry, Alias, Environment, Filesystem, Function and variable. You can also see the respective drives associated to its PSProvider. This means that if you are creating any variable it will be stored in variable: , If you are creating a function then it will be stored in Function:
check the below image, where i am going into respective drive and able to see the variable which i have created.
In conclusion, whatever variable/function/etc which I create in powershell gets stored in their respective drives.
vimstore is a one of the PSProvider which you get after connecting to VMware vCenter via PowerCLI. Do this, Connect-VIServer vCenter-ip and then run get-PSProvider cmdlet and you will see additional PSProviders are available to you. These providers are something which provides VMware Inventory and datastore resources to the POwerCLI or PowerShell.
So, After connecting to vCenter via PowerCli you can see additional PSDrives are available to you, provided by 2 additional PSProviders. I can do cd vmstore: and can actually list the available datastore in the datastore inventory (Simillar to how we list the directories and files in a path) or can list the host inventory.
Once you are connected you can follow below commands to create a New-PSDrvive with ‘Vimdatastore’ PSProvider.
Now you have DS: drive which is available to you and you can basically navigate through the same way you do it for any other drive.
Use below command to move data from your local drive to the VMware datastore using PowerCLI. Please note that i am already in DS: , If you are in any other drive then give proper path using vimdatastore drive
Note: This method is quite helpful in case you are trying to move things around from datastore and you can automate the move operation. also this is an alternate to certificate error which you may receive while moving data from Web Client. For ex, Operation failed when I tried to upload the same ISO using web client.
Use PowerCLI vimdatastore Psprovider and copy-datastoreitem cmdlet to work around this.