param(
 $hostIP="<hostIP>",
 #$esxusr="root", 
 #$esxpwd="pwd",
 $vibfile="NVIDIA.vib",
 $localpath="\\server\folder\NVIDIA"
 )

$remotefolder = "Nvidia"

#import PowerCLI cmdlets - load whole stack Get-Module -ListAvailable VM* | Import-Module 
if ((Get-Module | Where {$_.Name -eq "VMware.VimAutomation.Core"}) -eq $null)
{ Write-Output "Importing VMware.VimAutomation.Core Module ..."
 Import-Module VMware.VimAutomation.Core}
# ask for credentials
$cred = Get-Credential -Message ("Please enter credentials for ESXi host " + $hostIP)
# connect to ESXi host
Write-Output "Connecting to ESXi host" $($hostIP)
Connect-VIServer $hostIP -Credential $cred -Force
# get SI datastore details
$esxstore = Get-Datastore SI*
# create folder if doesn't exist already
Write-Output ("Check "+$remotefolder+" exists / create folder if not")
Write-Output ("Remote path = vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder)
if ( -not (Test-Path -Path ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder))) 
{ New-Item -ItemType directory -Path ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder) }
# check if vib file exists and if not copy across
Write-Output ("Check if "+$vibfile+" is present in "+($esxstore.Name)+" datastore / copy file if not")
#Write-Output ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder+"\"+$vibfile)
if ( -not (Test-Path -Path ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder+"\"+$vibfile))) 
{ Copy-DatastoreItem ($localpath+"\"+$vibfile) ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder) }
# disconnect from ESXi host
Write-Output "All Done. Disconnecting from ESXi host ..."
Disconnect-VIServer -Server $hostIP -Force -Confirm:$false



.