0

I'm using SSIS 2016 in VS 2015.

I'm using PowerShell (I can never get C# to work how I want it) to spit out the results to a variable.

This is the code im running:

$RootFolder = 'C:\DSB_Download'

[string]$Folder = Get-ChildItem $RootFolder | sort Name -Descending| 
select -ExpandProperty Name -First 1;

If ([string]::IsNullOrEmpty($Folder))
    {
        $result = "EmptyFolder";
        $result = $result -replace "`t|`n|`r",""
        $result = $result -replace " ;|; ",";";}
    Else
    {$result = $Folder;}

Write-Output $result;

All im doing is trying to return a string of "EmptyFolder" to a Result variable, this is then used in a Script task, where im checking the DTS Variable , (made from the Powershell variable)

the c# is doing this:

 string NoFolders = "EmptyFolder";

        if (LocalDrive == NoFolders)
        {
            Dts.Variables["User::WorkingDateString"].Value = WebDrive;

        }

So the C# if clause is looking for the string "EmptyFolder"

Great, however when I'm debugging this, I've noted that the SSIS Variable that holds the PowerShell result shows as this:

enter image description here

So the String is showing with \r\n at the end, and of course this doesn't match what the c# is looking for and its passed over.

as you can see the PowerShell is trying to replace the $result to remove the \r\n but its not doing anything.

Does anyone have any ideas how I can get rid of this, and have the string variable exactly as it should be?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
JayBay2279
  • 395
  • 1
  • 3
  • 9
  • Does the `|` work as an or with the replace? This example doesn't use the syntax https://stackoverflow.com/a/19128003/181965 – billinkc Sep 08 '17 at 20:40
  • Also, it looks like you're attempting to get the contents of a folder and/or test for the existence of a folder in C#, would you rather have that solution? – billinkc Sep 08 '17 at 20:43

0 Answers0