Getting error: You cannot call a method on a null-valued expression.

Nov 1, 2014 at 6:06 PM
Edited Nov 1, 2014 at 6:09 PM
Not sure what I've done wrong, all relevant directories exist, 7zip is in the default location, and I'm running powershell with elevated priveleges.

Other possibly relevant info:
Windows 7 64 bit
7zip version 9.20.0.0
Powershell 2.0

Any guidance on where I've gone wrong would be greatly appreciated. Thanks!

Below is the command I've plugged in, and the output I've received:
PS I:\Dropbox\Backups\7zBackup> .\7zBackup.ps1 --type full --rotate 4 --selection 7zBackup.selection.txt

 ------------------------------------------------------------------------------

  7zBackup.ps1 ver. 1.9.8-Stable (http://7zbackup.codeplex.com)

 ------------------------------------------------------------------------------

 Started         :  11/01/2014 10:03:19
 Backup Type     :  full
 Archive Name    :  JUPITER-full-20141101-1003.7z
 Archive Type    :  7z
 Destination     :  I:\Backups\Jupiter
 Selection       :  I:\Dropbox\Backups\7zBackup\7zBackup.selection.txt
 Recursion Depth :  100
 Archive Attrs   :  Will be cleared
 Rotate          :  Keep last 4 archive(s)
 7Zip Switches   :  -bd -ssw -mx1 -md=96m -mmt=6 -mtc=on -mf=off -slp -scsUTF-8 -sccUTF-8

 ------------------------------------------------------------------------------
 Backup from sources
 -------------------------------
You cannot call a method on a null-valued expression.
At I:\Dropbox\Backups\7zBackup\7zBackup.ps1:1774 char:34
+     $alias=$line.Split("|")[1].Split <<<< ("=")[1]
    + CategoryInfo          : InvalidOperation: (Split:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

 -  <== F:\Docs1
   Alias  already in use. Skipping selection of F:\Docs1
You cannot call a method on a null-valued expression.
At I:\Dropbox\Backups\7zBackup\7zBackup.ps1:1774 char:34
+     $alias=$line.Split("|")[1].Split <<<< ("=")[1]
    + CategoryInfo          : InvalidOperation: (Split:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

 -  <== F:\Docs2
   Alias  already in use. Skipping selection of F:\Docs2
 There are no selectable sources to backup. Quitting
True
PS I:\Dropbox\Backups\7zBackup>  $Host.Version.Major
2
PS I:\Dropbox\Backups\7zBackup>
Here are all of the variables set in 7zBackup-vars.ps1:
Set-Variable -name BkDestPath -value "I:\Backups\Jupiter\" -scope 1
Set-Variable -name BkArchivePrefix -value ($Env:Computername) -scope 1
Set-Variable -name BkArchiveType -value "7z" -scope 1
Set-Variable -name BkLogFile -value "I:\Dropbox\Backups\log.txt" -scope 1
Set-Variable -name Bk7ZipBin -value (Join-Path $Env:ProgramFiles "\7-zip\7z.exe") -scope 1
Set-Variable -name Bk7ZipSwitches -value "-bd -ssw -mx1 -md=96m -mmt=6 -mtc=on -mf=off -slp -scsUTF-8 -sccUTF-8" -scope 1
And here are the selections and variables set in 7zBackup.selection.txt. These are both freshly created directories, with a few dummy .txt files sprinkled around, set up for testing this script.
includesource=F:\Docs1
includesource=F:\Docs2
Coordinator
Nov 1, 2014 at 6:11 PM
Hi wolgan08,
there is clearly an error in your dummy.txt selection file. Include source directive is incomplete as it is missing it's alias part.
Replace yours
includesource=F:\Docs1
includesource=F:\Docs2
with
includesource=F:\Docs1|alias=Doc1
includesource=F:\Docs2|alias=Doc2
The "alias" part is necessary as it gives the subcontainer name in the archive file.

Nevertheless you have pointed out that I should do a better check on correctness of selection file.
Marked as answer by Anlan on 11/1/2014 at 10:15 AM
Nov 1, 2014 at 6:35 PM
Edited Nov 1, 2014 at 6:35 PM
Doh! I need to read things more carefully.. Sorry.

I've replaced the line verbatim with your example above, and the script error has gone away, but the "Alias already in use." warning is still coming up.

I apologize, still learning some of the basics.
PS I:\Backups\7zBackup> .\7zBackup.ps1 --type full --rotate 4 --selection 7zBackup.selection.txt

 ------------------------------------------------------------------------------

  7zBackup.ps1 ver. 1.9.8-Stable (http://7zbackup.codeplex.com)

 ------------------------------------------------------------------------------

 Started         :  11/01/2014 10:28:19
 Backup Type     :  full
 Archive Name    :  JUPITER-full-20141101-1028.7z
 Archive Type    :  7z
 Destination     :  I:\Backups\Jupiter
 Selection       :  I:\Backups\7zBackup\7zBackup.selection.txt
 Recursion Depth :  100
 Archive Attrs   :  Will be cleared
 Rotate          :  Keep last 4 archive(s)
 7Zip Switches   :  -bd -ssw -mx1 -md=96m -mmt=6 -mtc=on -mf=off -slp -scsUTF-8 -sccUTF-8

 ------------------------------------------------------------------------------
 Backup from sources
 -------------------------------
 -  <== F:\Docs1
   Alias  already in use. Skipping selection of F:\Docs1
 -  <== F:\Docs2
   Alias  already in use. Skipping selection of F:\Docs2
 There are no selectable sources to backup. Quitting
True
PS I:\Backups\7zBackup>
Coordinator
Nov 2, 2014 at 9:49 AM
Hi wolgan08,
assuming you have not set the directive "workdrive" I guess you will find in your "C:" drive a directory named something like C:\~af01 ... this one is where junction points are created. The error you are receiving is telling you that junction points in that "root" directory are already present.

My suggestion is to delete that "tilde" root directory (PLEASE READ CAREFULLY HOW TO DELETE IT IN THE README FILE) and try to re-launch the script. I am pretty sure the error goes away.

Let me know.
Marked as answer by wolgan08 on 11/2/2014 at 3:18 AM
Nov 2, 2014 at 11:18 AM
That was it, working fantastic now, thank you!