Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this function that I would like to pass as a start-job call.

function Write-Registry {
param($RegFileContents, $UserSid)
$TempRegFile = Get-TempRegFilePath
$regFileContents = $regFileContents -replace 'HKEY_CURRENT_USER', "HKEY_USERS$userSid"
$regFileContents | Out-File -FilePath $TempRegFile    
$p = Start-Process -FilePath C:Windows
egedit.exe -ArgumentList @('/s', $TempRegFile) -PassThru
do { Start-Sleep -Seconds 1 } while (-not $p.HasExited)    
Remove-Item -Path $TempRegFile -Force
}

As of now I call this function using two parameters, which works fine.

Write-Registry -RegFileContents $regFileContents -UserSid $userid

But I'd like to call it as a Start-Job; and can't seem to find how to do it properly.

If someone can help me, thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

Since a function and a scriptblock are the same thing:

function hi ($a, $b) { echo $a $b }                         

start-job $function:hi -args 1,2 | Receive-Job -wait -auto

1
2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...