I've created a PS function which generates a CSV using a path provided as a parameter.

A preceding function creates the path on the C: drive if it doesn't already exist.

If the path already exists the file is saved fine. However, if the directory is created before the CSV is exported then I get the error:

```
Export-Csv : The specified wildcard character pattern is not valid: System.Object[]

```

If I write out the path it returns as: System.Object[]\filename.csv

The input parameter is a String, the path name returned by the preceding function is a String and when I use $OutputDirectory.GetType() I get a String with base type System.Object.

When I use a literal string then function works fine, even when a new directory is created. It's just when the path returned by the function is used as the value for param $OutputDirectory that I get this error.

```
Function New-Output{

[CmdletBinding()]
param (
    [Parameter(Mandatory=$true)]
    [object]
    $ResultsObject,
    [Parameter(Mandatory=$true)]
    [string]
    $OutputDirectory
)

$OutputDirectory.GetType() # String / BaseType = System.Object

$OutputFileName = Join-Path $OutputDirectory.ToString() -ChildPath "\output.csv"

# output the results
$ResultsObject.Node | Select-Object total, errors, failures | Export-Csv -Path $OutputFileName - 
NoTypeInformation

}

```

So when a directory is first created Export-Csv thinks that $OutputDirectory is type System.Object.

Here's the function which creates the directory. This seems to work fine and returns a string:

```
Function New-TestResultsOutputDirectory{

[CmdletBinding()]
[OutputType([String])]
param (
    [Parameter(Mandatory=$true)]
    [object]
    $ResultsObject
)

# set the test name, date and time values from the test-results node
$testSuiteDirectory = Split-Path ($ResultsObject.Node.name).ToString()

# set the attributes for the output directory
$testDate = $testResults.Node.date.ToString().Replace("-","")
$testTime = $testResults.Node.time.ToString().Replace(":","")
$testSuiteName = (Split-Path (Split-Path ($ResultsObject.Node.name).ToString() -Parent) -Leaf).Replace(".","_")
$resultsDirectory = ($testSuiteName + "_" + $testDate + "_" + $testTime).ToString()
$outputDirectory = (Join-Path $testSuiteDirectory -ChildPath $resultsDirectory).ToString()

# check if the output path exists
$outputPathExists = Test-Path $outputDirectory

# create the results output path if it does not exists
if(!$outputPathExists){

    # create the directory
    New-Item -Path $outputDirectory -ItemType "directory"

    # check if the directory has been created
    $outputPathExists = Test-Path $outputDirectory

    while($outputPathExists -eq $false){

        # wait for 5 seconds
        Start-Sleep -Seconds 5

        # recheck if the directory has been created
        $outputPathExists = Test-Path $outputDirectory

    }

}

return $outputDirectory
}

```

Any help appreciated. Thanks