Created
January 28, 2019 14:01
-
-
Save AndrewPla/22aced2413e91d15a449c59c021d7176 to your computer and use it in GitHub Desktop.
Download the latest backup from TOPdesk using PowerShell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credential needs to | |
$Credential = Get-Credential -Message 'enter TOPdesk operator credential with WebDAV permissions.' | |
$OutputFolder = 'C:\path\to\folder' | |
$tdurl = 'company.topdesk.net' | |
$psDriveParams = @{ | |
PSProvider = 'FileSystem' | |
Root = "\\$tdUrl@SSL\webdav" # ex: '\\contoso.topdesk.net@SSL\webdav' | |
Credential = $Credential | |
Name = 'TOPdesk' | |
} | |
New-PSDrive @psDriveParams | |
# Grab the latest file. | |
$file = Get-ChildItem TOPdesk:\database_backup -filter *.bak | | |
Sort-Object LastWriteTime | | |
Select-Object -last 1 | |
if (-not $file){ | |
throw 'no backup file found. Run Get-ChildItem Topdesk:\database_backup to look for more files' | |
} | |
# clean up our psdrive that we created. | |
Remove-PSDrive 'TOPdesk' | |
# Let's create our webclient that we will use to download the file. | |
$WebClient = New-Object system.net.webclient | |
# We need to add a TOPdesk credential in order for TOPdesk to send us the file. | |
$WebClient.Credentials = $Credential | |
# Download the file by using the downloadfile method on the web client. | |
# We provide it with the url of the file and the output filepath | |
$WebClient.DownloadFile("https://$tdUrl/webdav/database_backup/$($file.name)", "$($OutputFolder)\$($file.name)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment