It's not possible. PowerShell is a plain console application as any other, it's not an API.
As @Bill_Steward suggested, have the PowerShell script output its results to a file and read that back in Inno Setup:
function CheckHost(var ErrorMessage: string): Boolean;
var
Parameters: string;
TempPath: string;
AErrorMessage: AnsiString;
ResultCode: Integer;
begin
TempPath := ExpandConstant('{tmp}\checkHost.err');
Parameters :=
'-ExecutionPolicy bypass -File "C:\path\to\script\checkHost.ps1" ' +
'-ErrorFile "' + TempPath + '"';
Result :=
Exec('powershell.exe', Parameters, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and
(ResultCode = 0);
if not Result then
begin
if LoadStringFromFile(TempPath, AErrorMessage) then
begin
ErrorMessage := AErrorMessage;
end;
end;
DeleteFile(TempPath);
end;
The above is based on How to get an output of an Exec'ed program in Inno Setup?
Use the function like:
var
ErrorMessage: string;
begin
if CheckHost(ErrorMessage) then
begin
MsgBox('Host check succeeded', mbInformation, MB_OK);
end
else
begin
MsgBox(ErrorMessage, mbError, MB_OK);
end;
end;
The PowerShell script may look like:
param (
$errorFile
)
if (checkHost())
{
exit 0
}
else
{
Set-Content -Path $errorFile -Value "Host check failed for some reason"
exit 1
}
Though, as @Bill_Steward mentioned too, it's quite possible that you can implement your check in pure Pascal Script. But that's for a different question.