- Community Home
- >
- Software
- >
- HPE OneView
- >
- OneView Backup Script - powershell Invoke-Rest
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2020 07:20 AM
07-31-2020 07:20 AM
Hi all, im trying trying to create a script with powershell using Invoke-Rest and having an odd issue. When i run the script i get the download.uri location but when i use the to download uri the file size appears to be different than when i download from the gui. If I change the encoding option to ascii the file size is the same as when i download through the gui. However, when i upload the file i create from the api, to the appliance, it fails verification. Most of the code is below, any advice? This is the first time i've tried downloading through powershell so not sure if im missing a step. Thanks,
#Kick off the backup
$uri = $url + "/rest/backups"
$data = Invoke-RestMethod -Method POST -Headers $auth -Uri $uri
#Download backup from download uri
$data = Invoke-RestMethod -Method GET -Headers $auth -Uri $uri
$data.members[0]
$uri1 = $url + $data.members[0].taskUri
DO{
$taskState = Invoke-RestMethod -Method GET -Headers $auth -Uri $uri1
Write-Progress -Activity "Creating backup..." -Status "% Complete: " -PercentComplete $taskState.percentComplete
} Until ($taskState.taskState -eq "Completed")
Write-Host "Location o download uri" -ForegroundColor Green
$data.members[0].downloadUri
$download = $data.members[0].downloadUri
$uri = $url + $download
$auth.Add("Accept", 'application/octetstream;q=0.8,application/json')
$auth.Add("Content-type", 'text/plain')
$auth.Add("Content-Length", '0')
#download the file
$data = Invoke-RestMethod -Method GET -Headers $auth -Uri $uri -Verbose
#shorten the name of the saved file
$name = $download.IndexOf("/t")
$newName = $download.Substring($name+1)
$newName
$data | Out-File -FilePath .\"$newName".bkp -Encoding ascii
Solved! Go to Solution.
- Tags:
- API
- backup
- powershell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2020 03:41 PM
07-31-2020 03:41 PM
Re: OneView Backup Script - powershell Invoke-Rest
Hello @thecakeisalie , and welcome to the HPE OneView communities.
Is there any reason why you cannot use the existing HPE OneView PowerShell library? We already have a Cmdlet that does this for you: New-OVBackup (legacy CMdlet: New-HPOVBackup).
You can get the HPE OneView PowerShell Library from the PowerShell Gallery.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2020 07:22 PM
07-31-2020 07:22 PM
Re: OneView Backup Script - powershell Invoke-Rest
Well well, we meet at last Mr. Lynch... Thanks for the frequent solutions on other posts, theyve assited me in the past on a variety of issues!
I'm well aware of the powershell library and do use the iLo and bios commandlets as they can be downloaded from HPE's website. However, the current org im working for doesnt allow downloads from github at the moment so im using this as an oppurtunity to reinvent the wheel a little instead of bypassing the current security policy. It's also a bit of an excercise in "can i get this to work" now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2020 08:27 PM
08-01-2020 08:27 PM
SolutionExcept the library isn't on Github for customers to download and use. It is the source. The final customer version is digitally signed and supported by HPE. Sure, someone could download it from Github, but then it isn't digitally signed and certainly open for someone to modify at their discretion.
You can certainly look at the source for New-OV Backup for how the library does it. But I would suggest you concider using the library already provided.
And the reason why the upload fails is due to the fact the upload expects a multi-partform binary. Which Invoke-RestMethod does not support.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2020 06:04 AM
08-04-2020 06:04 AM
Re: OneView Backup Script - powershell Invoke-Rest
Aweomse, thanks for the tip! I'll look for the HPE supported commandlets. The company I'm with allows us to download from HPE so I probably just need to dig around a bit more.
Thanks for the guidance on the invoke-rest command though! Solves that mystery. As always, the advice is much appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2020 09:34 AM
08-04-2020 09:34 AM
Re: OneView Backup Script - powershell Invoke-Rest
As I stated above, the HPE OneView PowerShell library is only located on PowerShell Gallary, which is a Microsoft owned and operated site. They allow anyone to publish scripts and modules there. However, they must have a valid account. All HPE PowerShell libraries are located here, under the "hp.powershell" account. So if you go looking on hpe.com, you will not find the HPE OneView PowerShell library hosted there.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
