I have an "Execute Process Task" that calls Powershell and checks if a folder is empty. I'm wanting the SSIS job to fail if $false is returned.

Here is the code

param ([string] $FolderLocation)

$FolderLocation = 'C:\Temp\IsFolderEmpty\'

if( (Get-ChildItem $FolderLocation | Measure-Object).Count -eq 0)
    #Folder Empty
    return $true

} Else {

    return $false


Any time I run this in SSIS, it always runs whether $true or $false is returned. I've tried creating a new variable and using it in the StandardOutputVariable but haven't had any luck.

  • 1
    Which problem would you rather solve: how to check if a folder is empty or how do I get a true/false returned from this execute package task? – billinkc Feb 20 at 16:52
  • I'd like to check if a folder is empty in SSIS and if it isn't, fail the job – jdids Feb 20 at 17:03

Try using a Script Task to check the value of the SSIS variable that is set as the StandardOutputVariable of the Execute Process Task. If this value is false the Dts.Events.FireError method raises an error event that can be used to fail the package. The code below is an example of this using C#, where an error is raised when the variable is false. The SSIS variable will need to be set in the ReadOnlyVariables field of the Script Task to allow it to be accessed.

    if (!Convert.ToBoolean(Dts.Variables["User::YourVariable"].Value))
        Dts.Events.FireError(0, "Error", "Error Raised from Folder Check", null, 0);
  • Thanks! Doing this in C# makes more sense. This got me over the hump – jdids Feb 22 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.