Skip to content

Instantly share code, notes, and snippets.

@AF250329
Created April 28, 2022 17:48
Show Gist options
  • Save AF250329/9b01b47771bffbe1a88ef05166b3893b to your computer and use it in GitHub Desktop.
Save AF250329/9b01b47771bffbe1a88ef05166b3893b to your computer and use it in GitHub Desktop.
Start-Job: Call another functions in a script
function Base-Function {
PARAM(
[string]
$PathToFile
)
if (Test-Path -Path $PathToFile) {
Write-Host "Exist"
}
}
function CopyFile {
PARAM(
[string]
$SourcePath,
[string]
$TargetPath
)
Base-Function -PathToFile $SourcePath
Base-Function -PathToFile $TargetPath
Write-Host "I will copy file from $SourcePath to $TargetPath"
}
function Main-Function {
$copyFileArgs = @{
"SourcePath" = "C:\Windows\notepad.exe"
"TargetPath" = "C:\Temp\notepad.exe"
}
Start-Job -ScriptBlock ${Function:CopyFile} -ArgumentList $copyFileArgs
}
Main-Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment