Help with function

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ipessa100
Posts: 1
Last visit: Sat Apr 09, 2016 3:04 pm

Help with function

Post by ipessa100 »

Hi,

I want to put this command Get-HotFix KB3133977,KB3123479 -ComputerName machine1,machine2 in a function ... I tried this but it didn't work:

function Get-KBUpdates
{

param (
[string]$machines,
[string]$updates
)


$machines = Get-Content "c:\machines.txt"
$updates = Get-Content "c:\kbupdates.txt"


}

Get-HotFix $updates -ComputerName $machines
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Help with function

Post by jvierra »

You are never calling your function and the "Get-HoFix" is not inside the function.

Start by reviewing this: https://technet.microsoft.com/en-us/lib ... 47829.aspx
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Help with function

Post by dan.potter »

ipessa100 wrote:Hi,

I want to put this command Get-HotFix KB3133977,KB3123479 -ComputerName machine1,machine2 in a function ... I tried this but it didn't work:

function Get-KBUpdates
{

param (
[string]$machines,
[string]$updates
)


$machines = Get-Content "c:\machines.txt"
$updates = Get-Content "c:\kbupdates.txt"


}

Get-HotFix $updates -ComputerName $machines
you have it backwards, array of machines goes outside the function. get-hotfix goes inside the function.

Play with this.

function Get-KBUpdates
{

param($computername)

get-hotfix... $computername

}

Get-KBUpdates $machines
This topic is 7 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked