Powershell Error

I am getting this error for the below script.

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\User> cd .\Desktop\KB951550
PS C:\Users\User\Desktop\KB951550> $hotfix=Get-ChildItem -name KB*
PS C:\Users\User\Desktop\KB951550> $fileinfo=Get-ChildItem $hotfix
PS C:\Users\User\Desktop\KB951550> $state = Get-HotFix -ID $fileinfo.basename
Get-HotFix : This command cannot find hot-fix on the machine 'localhost'. Verify the input and Run your command again.
At line:1 char:20
+ $state = Get-HotFix <<<<  -ID $fileinfo.basename
    + CategoryInfo          : ObjectNotFound: (:) [Get-HotFix], ArgumentException
    + FullyQualifiedErrorId : GetHotFixNoEntriesFound,Microsoft.PowerShell.Commands.GetHotFixCommand

PS C:\Users\User\Desktop\KB951550>

    Script: RTI Patch Verification Script for Windows 7
    Creation Date: 7/16/2010
    Last Modified: 7/16/2010
    This script determines if the patch located in this directory has been applied to the OS.
    Patches must be named after their respective KB article for this to work.

# Find the KB file to check for...
$hotfix=Get-ChildItem -name KB*

# Find the KB file WITHOUT the extension, accessable through $fileinfo.basename
$fileinfo=Get-ChildItem $hotfix

# Query the list of HotFixes for this KB Article...
$state = Get-HotFix -ID $fileinfo.basename

# Compare the KB Article here with the results of our query with that HotFixID to generate Success or Failure
if ($state.HotFixId -ne $fileinfo.basename)
    Write-Output "This Hotfix is not installed."
    Write-Output "Hotfix successfully installed."

Open in new window

LVL 14
Dhiraj MuthaLevel DAsked:
Who is Participating?
Dhiraj MuthaLevel DAuthor Commented:
I resolved the issue myself, I was using Powershell 1.0.
Chris DentPowerShell DeveloperCommented:
It'll throw that if the hotfix ID you specified does not exist.

You'll have to echo out $fileinfo.basename before it's called to see if the value you're passing is why. Or do you need to determine if that command worked or not?

The only thing I can see if you should probably quote out KB* since it is a string. For instance:
$hotfix=Get-ChildItem -name KB*
should be
$hotfix=Get-ChildItem -name "KB*"
Dhiraj MuthaLevel DAuthor Commented:
I think $fileinfo.basename  is empty, how do I resolve it?

Second, is there a command called Get-Hotfix?
Dhiraj MuthaLevel DAuthor Commented:
I resolved the issue myself, I was using Powershell 1.0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.