I have this function:
function getHDriveSize($usersHomeDirectory)
{
$timeOutSeconds = 600
$code =
{
$hDriveSize = powershell.exe $script:getHDriveSizePath - path $usersDirectory
return $hDriveSize
}
$job = Start-Job -ScriptBlock $code
if (Wait-Job $job -Timeout $timeOutSeconds)
{
$receivedJob = Receive-Job $job
return $receivedJob
}
else
{
return "Timed Out"
}
}
When I call it, I get a CommandNotFoundException:
-path : The term '-path' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
However, the line:
$hDriveSize = powershell.exe $script:getHDriveSizePath - path $usersDirectory
by itself works fine.
How can I call the powershell script within the $code variable successfully?
- pathcannot work. Second, it appears that$script:getHDriveSizePathseems to not exist, so PowerShell just gets an empty string there and tries executing-path. Third, your function name is way off and should probably be something likeGet-HDriveSizeinstead.