Newb needs help
I'm certainly a newb to Powershell scripts. But when I right-click the backupPFsense.ps1 file and choose run in Powershell, a window pops up and immediately goes away and no backup is created. If I open PowerShell first and run it from there. I just get this:
backupPFsense.ps1 : The term 'backupPFsense.ps1' is not recognized as the name of a cmdlet, function, script file, or
operable program.
I have all the variables set inside the file, but I wanted to run it manually before setting up the TaskScheduler job.
What am I doing wrong?
Tried the v2 auto script first. Same thing.
Okay. So turns out it was a permission problem with PowerShell not allowing scripts to run. I fixed that, but I am getting this error when running the script now:
The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command
name, a script block, or a CommandInfo object.
At C:\pfsensebackup\backupPFsense.ps1:83 char:5
+ & $pushoverapp message="$message";
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : BadExpression
Any ideas?
Tried the v2 script now that I have scripts able to run....after choosing the backup files location it just blew up:
Unable to find type [System.Windows.Forms.MessageBox].
At C:\pfsensebackup\pfsensebackupv2.ps1:20 char:16
+ null = [System.Windows.Forms.MessageBox]::Show('On the next p ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Forms.MessageBox:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Unable to find type [System.Windows.Forms.MessageBox].
At C:\pfsensebackup\pfsensebackupv2.ps1:52 char:17
+ $null = [System.Windows.Forms.MessageBox]::Show('Configuratio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Forms.MessageBox:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Add-Content : Access to the path 'C:\' is denied.
At C:\pfsensebackup\pfsensebackupv2.ps1:208 char:1
+ Add-Content -Path $log -Value "-------------------------------------- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\:String) [Add-Content], UnauthorizedAccessException
+ FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand
Add-Content : Access to the path 'C:\' is denied.
At C:\pfsensebackup\pfsensebackupv2.ps1:209 char:1
+ Add-Content -Path $log -Value "Backup process started"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\:String) [Add-Content], UnauthorizedAccessException
+ FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand
The property 'usepush' cannot be found on this object. Verify that the property exists and can be set.
At C:\pfsensebackup\pfsensebackupv2.ps1:212 char:5
+ if ($config.usepush = "y") + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
Add-Content : Access to the path 'C:\' is denied.
At C:\pfsensebackup\pfsensebackupv2.ps1:119 char:2
+ Add-Content -Path $log -Value $logMessage
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\:String) [Add-Content], UnauthorizedAccessException
+ FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand
Exception calling "SecureStringToBSTR" with "1" argument(s): "Value cannot be null.
Parameter name: s"
At C:\pfsensebackup\pfsensebackupv2.ps1:131 char:5
+ $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToB ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Cannot find an overload for "PtrToStringAuto" and the argument count: "1".
At C:\pfsensebackup\pfsensebackupv2.ps1:132 char:5
+ $plainpw = [System.Runtime.InteropServices.Marshal]::PtrToStringA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
-u : The term '-u' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:2
+ -u -p -s -o
+ ~~
+ CategoryInfo : ObjectNotFound: (-u:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Write-Log : Cannot bind argument to parameter 'text' because it is an empty string.
At C:\pfsensebackup\pfsensebackupv2.ps1:137 char:18
+ write-log -text $cmdOutput -type AppOutput
+ ~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Write-Log], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Write-Log
Add-Content : Access to the path 'C:\' is denied.
At C:\pfsensebackup\pfsensebackupv2.ps1:119 char:2
+ Add-Content -Path $log -Value $logMessage
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\:String) [Add-Content], UnauthorizedAccessException
+ FullyQualifiedErrorId : GetContentWriterUnauthorizedAccessError,Microsoft.PowerShell.Commands.AddContentCommand
The property 'usepush' cannot be found on this object. Verify that the property exists and can be set.
At C:\pfsensebackup\pfsensebackupv2.ps1:187 char:6
+ if ($config.usepush = "y")
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
4th time's almost a charm. Seeing the denied access to C: I moved the scripts to the D: drive. That allowed me to get through the v2 script's variable pop-ups. Then I get this error in PowerShell:
Import-Module : Cannot bind argument to parameter 'Name' because it is an empty string.
At D:\pfsensebackup\pfsensebackupv2.ps1:216 char:23
+ Import-Module $modulepath
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Import-Module], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Impo
rtModuleCommand
I think this is related to choosing No on using pushover. The script chokes after saying no, I guess.
The script seems to still be running in the PS window (no command input line has returned). The log just says
Backup process started
[11/09/2023 08:38:04] - INFO Executing the backup command
UPDATE....after several minutes the script finished with this error in PS:
Send-PushoverMessage : The term 'Send-PushoverMessage' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At D:\pfsensebackup\pfsensebackupv2.ps1:191 char:3
+ Send-PushoverMessage $($message) -title $($Config.pushsubject ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Send-PushoverMessage:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
And the log says:
[11/09/2023 08:43:05] - AppOutput
pfSense Backup Tool v2.6.0 by Koen Zomers
Connecting using protocol version 2.7.0
Authenticating
Error: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
[11/09/2023 08:43:05] - ERROR ERROR running copy exe
[11/09/2023 08:43:05] - INFO Push notification sent
Obviously, the connection to my firewall fouled. Maybe there is something further I need to do for pfSenseBackup.exe to function.
Okay. Hopefully last message, then I'll let you catch up. :-D When I went through and did all the setup for Pushover I got a successful backup. But still an error in PS:
Import-Module : Cannot bind argument to parameter 'Name' because it is an empty string.
At D:\pfsensebackup\pfsensebackupv2.ps1:216 char:23
+ Import-Module $modulepath
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Import-Module], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Impo
rtModuleCommand
Backup complete.
Send-PushoverMessage : The term 'Send-PushoverMessage' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At D:\pfsensebackup\pfsensebackupv2.ps1:191 char:3
+ Send-PushoverMessage $($message) -title $($Config.pushsubject ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Send-PushoverMessage:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
And no Pushover message received.