Hi
I'm trying to write a script who backups the VMs of our helpdesk. They have some testmachines, who need only a basic backup.
The Script:
function backupvm($name, $destination) { $test = Test-Path $destination if($test -eq $false) { mkdir $destination } Copy-DatastoreItem MyDS:\$name\* $destination } # Set variables $server = "vCenterServer" $folder = "Testclients CLC" $ds = "datastore" $backupdestination = "M:\TresY\testbackup" # Connect to $Server connect-viserver $server # Generates a PSDrive $datastore = Get-Datastore $ds New-PSDrive -Name MyDS -PSProvider ViMdatastore -Root '\' -location $datastore # Suspends all started VMs Write-Host "VMs are now backupped:" Get-VM -location $folder | Foreach-Object { if($_.PowerState -eq "PoweredOn") { Suspend-VM -VM $_.Name -Confirm:$false backupvm $_.Name $backupdestination"\"$_ Start-VM -VM $_.Name -Confirm:$false Write-Host $_.FullName } Else { backupvm $_.Name $backupdestination"\"$_ Write-Host $_.Name } }
When I execute it, followed error arrives:
Copy-DatastoreItem : 12.04.2011 08:42:24 VimDatastore Download of fil
e 'https://vCenterServer:443/folder%2ft008002%2fvmware.log?dcPath=
Biel&dsName=DateStore' failed. Error message: The remote serv
er returned an error: (401) Unauthorized.
At C:\Temp\powershell\backups-testesxi21.ps1:19 char:23
+ Copy-DatastoreItem <<<< -Item MyDS:\$name\* -Destination $destination
+ CategoryInfo : NotSpecified: (:) [Copy-DatastoreItem], VimExcep
tion
+ FullyQualifiedErrorId : Client20_StorageServiceImpl_DownloadFile_Downloa
dFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyDatastoreItem
From MyDS to MyDS i can copy the files without problmes. But to my local path on M:\TresY\testbackup i receive the error.
Any ideas?
Thanks!
Yannick