You cannot call a method on a null-valued expression.

Jul 14, 2011 at 3:52 PM

Hello member crew of imagepachers,

I've the following problem when running script...

Script's starts ..after a few seconds got this error...

You cannot call a method on a null-valued expression.

I didn't changed nothing on the script! Path to sources\install.WIM file is ok.

.\imagepatcher.ps1 -imagefile:"d:\7work\dvd\sources\install.wim" -dbg:yes -patchimages:all

Greets

Jun 22, 2012 at 12:59 AM

I am getting the same error, but it is instant and as soon as it starts downloading.  Here is some of the output:

 

You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:172 char:10+          $writer.Flush()+          ~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:173 char:10+          $writer.Close()+          ~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
Get-ChildItem : Cannot find path 'D:\D:\wsusscn2.cab' because it does not exist.At D:\imagepatcherworking.ps1:181 char:7+       ls $fileName+       ~~~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (D:\D:\wsusscn2.cab:String) [Get-ChildItem], ItemNotFoundException    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
New-Object : Exception calling ".ctor" with "2" argument(s): "The given path's format is not supported."At D:\imagepatcherworking.ps1:148 char:20+          $writer = new-object System.IO.FileStream $fileName, "Create"+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:156 char:13+             $writer.Write($buffer, 0, $count);+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:172 char:10+          $writer.Flush()+          ~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.At D:\imagepatcherworking.ps1:173 char:10+          $writer.Close()+          ~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException    + FullyQualifiedErrorId : InvokeMethodOnNull
Get-ChildItem : Cannot find path 'D:\D:\static.xml' because it does not exist.At D:\imagepatcherworking.ps1:181 char:7+       ls $fileName+       ~~~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (D:\D:\static.xml:String) [Get-ChildItem], ItemNotFoundException    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Missing wsusscn2.cab - probably download problem, check your internet connectivity

It is interesting that its doubling the drive letter.  (i.e. D:\D:\static.xml instead of D:\static.xml)  I in no way understand scripting so I wouldn't even know where to look to fix this.

Jun 28, 2012 at 3:25 AM

The author doesn't maintain this repository here, but I still post stuff here.  I'm attempting to reproduce this, I'll let you know what I find.

Jun 28, 2012 at 3:31 AM

You can get my customized one here http://sdrv.ms/LSdt5m

Main difference is that mine only does Critical & Security Updates.

Jul 6, 2012 at 5:19 PM

Thanks, I'll give that a try.  Critical & Security are all I really need.

Jul 13, 2012 at 5:37 PM

Will this script also apply Microsoft Office security updates?

Jul 13, 2012 at 6:00 PM
Nope. Don't know if it can be done.

Connected by DROID on Verizon Wireless


-----Original message-----
From: JamesRivett <[email removed]>
To: Peter Wood <[email removed]>
Sent: Fri, Jul 13, 2012 16:38:04 GMT+00:00
Subject: Re: You cannot call a method on a null-valued expression. [imagepatcher:265165]


From: JamesRivett

Will this script also apply Microsoft Office security updates?

Read the full discussion online<http://imagepatcher.codeplex.com/discussions/265165#post864995>.

To add a post to this discussion, reply to this email ([email removed]<mailto:[email removed]?subject=[imagepatcher:265165]>)

To start a new discussion for this project, email [email removed]<mailto:[email removed]>

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings<https://imagepatcher.codeplex.com/subscriptions/thread/project/edit> on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

________________________________
Oct 31, 2012 at 8:19 PM

Hi,

I found the error and I posted the repaired script on my blog. http://elvis.em-soft.si

 

Feb 13, 2013 at 2:57 PM
Hi,

I'm also trying to run this script to patch a wim file, but hitting this error:

You cannot call a method on a null-valued expression.
At C:\ImagePatcherv2.ps1:156 char:26
  • $writer.Write <<<< ($buffer, 0, $count);
    • CategoryInfo : InvalidOperation: (Write:String) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull
This is repeated over and over again and finishes with:

Missing wsusscn2.cab - probably download problem, check your internet connectivity

Note: I checked the script and it downloads from these places shown in the excerpt from the imagepatcher.ps below.

write-debug "Downloading wsusscn2.cab"
Get-WebFile "http://download.windowsupdate.com/microsoftupdate/v6/wsusscan/wsusscn2.cab" $scriptpath $scriptpath $true
write-debug "Downloading static.xml"
Get-WebFile "http://optimalizovane-it.cz/support/static.xml" $scriptpath $scriptpath $true
if (!(test-path $scriptpath"\wsusscn2.cab")){
write-host "Missing wsusscn2.cab - probably download problem, check your internet connectivity"
I'm investigating and if I make progress I'll update here for the benefit of others who are stuck with the same issue.

Thanks,
Ian
Nov 27, 2013 at 12:01 AM
Edited Nov 27, 2013 at 12:37 AM
Just want to thank ElvisG for fixing the imagepatcher.ps1. I used the code fix in imagepatcherv2.ps1 and now am successfully patching only security and critical updates. (Or at least I hope that's what I am doing, if I am wrong, please let me know!! That is how I understand what I am doing by what I read on the site, not by analyzing the script)

Since I do not script in PS and relaly have no idea what I am looking at, this was very tedious and essentially amounted to line by line comparison.

I replaced the following code in imagepatcherv2.ps1 (lines 82-90):

if ($url.length -lt 1) {return}

$webfilename = $url.split("/")[$url.count-1]
$fileName = $downloadpath + "\" + $webfilename
write-debug $fileName
if((test-path $filename) -and -not $forcednld){
    write-host "$webfilename file already downloaded, will use the old one"
    return
} else {

with:

if ($url.length -lt 1) {return}

if ($url.length -lt 1) {return}

$posit = $url.IndexOf("//")
$webfilename = $url.Substring($posit + 2)
$posit = $webfilename.IndexOf("/")
do {
   $webfilename = $webfilename.Substring($posit + 1)
   $posit = $webfilename.IndexOf("/")
}
while ($posit -gt 0)
$fileName = $downloadpath + "\" + $webfilename
write-debug $fileName
if((test-path $filename) -and -not $forcednld){
    write-host "$webfilename file already downloaded, will use the old one"
    return
} else {

Hope this helps anyone else having issues with this amazing script. Thanks to all who contributed to it!!

I am curious if this line was meant to be duplicated:

if ($url.length -lt 1) {return}

if ($url.length -lt 1) {return}

??

Another quick question if anyone knows, what part of the script specifies security and critical updates only?

Thanks!

James