[SOLVED] Downloading Latest Backup File

So me being stupid.. I need to add hub ip and destination location to this section of the script right? I'm probably missing commas or..

param
(
[Parameter(Mandatory=$true)]
[string]$192.168.86.86,
[Parameter(Mandatory=$true)]
[string]$C:\Temp,
[string]$BackupNamePrefix = "hubitat_backup_",
[switch]$WhatIf
)

You don't need to modify the script at all. Just pass your hub's IP and backup destination as parameters. I chose to put the script into the same directory as my backup destination to keep it simple. I then scheduled a task to run "Powershell" periodically with arguments and startup directory.

.\Hubitat-Configuration-Backup.ps1 -HubHostname 192.168.1.20 -BackupDestination .\

Like @HAL9000 mentioned you don't need to change the script. You just need to add your hub's IP address and destination to the argument in task scheduler.

Screen Shot 2021-03-29 at 10.31.47 AM

Here's what I use for the argument:

.\Hubitat-Configuration-Backup.ps1 -HubHostname 192.168.86.25 -BackupDestination c:\hubitat\backups

I created a directory for the script and a sub-directory for the backups. The reason for the sub-directory is I have another scheduled task that cleans out the files that are older than 30 days.

Screen Shot 2021-03-29 at 10.44.55 AM

Here's the argument I'm using for deleting the old files.

/p "C:\hubitat\backup /s /d -30 /c "cmd /c del /q @file"

Thanks @HAL9000 and @Vettester for trying to help me. I'm still struggling though.
I created script (ps1 file, did not change anything in it). Created a folder for it and to make it simple..I'm using same folder for the backup files.
Then created scheduler.

My config is:
powershell
.\Hubitat-Configuration-Backup.ps1 -HubHostname 192.168.86.45 -BackupDestination
C:\Users\myusername\Documents\Hubitat

I scheduled it and powershell briefly opens but nothing happens. I'm not getting bu file to folder. Am I doing something wrong here?

EDIT: I tried to run it manually from my laptop and script works. I tried same thing with my 24/7 pc and it does not work. It flashes some red text in powershell window before it closes. So this seems to be more of a user rights problem or some kind of powershell issue in that pc.

Just a guess, but this might explain the difference ...

Ok.. I'm slowly getting there. Problem was because..

"Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first
-launch configuration is not complete. Specify the UseBasicParsing parameter and try again. "

... :crazy_face: so...opened IE and now script works at least when ran manually. Soon testing scheduler.

EDIT: and scheduler works now!!! Once again..thank you guys!! I really appreciate your help!

2 Likes