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>

<#
    .Info
    Script: RTI Patch Verification Script for Windows 7
    Creation Date: 7/16/2010
    Last Modified: 7/16/2010
    
    .Description
    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)
{
    $RTIFail=1
    Write-Output "This Hotfix is not installed."
}
Else
{
    $RTIFail=0
    Write-Output "Hotfix successfully installed."
}

Open in new window

LVL 14
Dhiraj MuthaLevel DAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?

Chris
0
GusGallowsCommented:
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*"
0
Dhiraj MuthaLevel DAuthor Commented:
I think $fileinfo.basename  is empty, how do I resolve it?

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dhiraj MuthaLevel DAuthor Commented:
I resolved the issue myself, I was using Powershell 1.0
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.