01.param(
02. $hostIP="<hostIP>",
03. #$esxusr="root",
04. #$esxpwd="pwd",
05. $vibfile="NVIDIA.vib",
06. $localpath="\\server\folder\NVIDIA"
07. )
08. 
09.$remotefolder = "Nvidia"
10. 
11.#import PowerCLI cmdlets - load whole stack Get-Module -ListAvailable VM* | Import-Module
12.if ((Get-Module | Where {$_.Name -eq "VMware.VimAutomation.Core"}) -eq $null)
13.{ Write-Output "Importing VMware.VimAutomation.Core Module ..."
14. Import-Module VMware.VimAutomation.Core}
15.# ask for credentials
16.$cred = Get-Credential -Message ("Please enter credentials for ESXi host " + $hostIP)
17.# connect to ESXi host
18.Write-Output "Connecting to ESXi host" $($hostIP)
19.Connect-VIServer $hostIP -Credential $cred -Force
20.# get SI datastore details
21.$esxstore = Get-Datastore SI*
22.# create folder if doesn't exist already
23.Write-Output ("Check "+$remotefolder+" exists / create folder if not")
24.Write-Output ("Remote path = vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder)
25.if ( -not (Test-Path -Path ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder)))
26.{ New-Item -ItemType directory -Path ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder) }
27.# check if vib file exists and if not copy across
28.Write-Output ("Check if "+$vibfile+" is present in "+($esxstore.Name)+" datastore / copy file if not")
29.#Write-Output ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder+"\"+$vibfile)
30.if ( -not (Test-Path -Path ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder+"\"+$vibfile)))
31.{ Copy-DatastoreItem ($localpath+"\"+$vibfile) ("vmstore:\"+$esxstore.Datacenter+"\"+$esxstore.Name+"\"+$remotefolder) }
32.# disconnect from ESXi host
33.Write-Output "All Done. Disconnecting from ESXi host ..."
34.Disconnect-VIServer -Server $hostIP -Force -Confirm:$false



.