0
Function SCP-ImplementationFiles($selectedDirectory, $fileName) {


Write-Host $rdfFile.GetType() $rdfFile.Name       
SCP-ImplementationFiles($directoryPrompt, $rdfFile.Name)

My Write-Host is providing output

System.IO.FileInfo file1.pdf

However when I pass it to my function, the 2nd parameter is always empty/null

I defined the function as close to the top of the script (in case it matters)

Not a duplicate of How do I pass multiple parameters into a function in PowerShell?

I am not trying to call a function from the prompt. I am trying to call the function from within the script. If I remove the ',' (comma), the editor tells me that there is a ',' missing


I've tried these functions to see if I did something wrong with the definition of my function

Function SCP-ImplementationFiles {
    param([string]$selectedDirectory, [string]$fileName)
    Write-Host $selectedDirectory
    Write-Host $fileName
}

Function SCP-ImplementationFiles([string]$selectedDirectory, [string]$fileName) {    
    Write-Host $selectedDirectory
    Write-Host $fileName
}

Function SCP-ImplementationFiles($selectedDirectory, $fileName) {    
    Write-Host $selectedDirectory
    Write-Host $fileName
}
software is fun
  • 7,286
  • 18
  • 71
  • 129
  • Could you provide the body of the `SCP-ImplementationFiles` Function? It's difficult to get the full picture without it – spicy.dll Jun 19 '19 at 20:28
  • Right now, I am just doing Write-Host and printing the parameters. – software is fun Jun 19 '19 at 20:29
  • Is that your actual full function body? Could you add the closing `}`? – spicy.dll Jun 19 '19 at 20:31
  • Are you getting an error message? How are you determining the value of `$fileName` is `$null`? – spicy.dll Jun 19 '19 at 20:42
  • I mouse over when debugging and it says $fileName =. I can also see that the second parameter is a part of the 1st one (separated by a space) – software is fun Jun 19 '19 at 20:47
  • 3
    You are passing an array using `SCP-ImplementationFiles ($directoryPrompt, $rdfFile.Name)`. Omit parentheses as well as any comma, call it as `SCP-ImplementationFiles $directoryPrompt $rdfFile.Name` – JosefZ Jun 19 '19 at 20:53
  • 3
    Possible duplicate of [How do I pass multiple parameters into a function in PowerShell?](https://stackoverflow.com/questions/4988226/how-do-i-pass-multiple-parameters-into-a-function-in-powershell) *I am not trying to call a function from the prompt. I am trying to call the function from within the script.* There is no difference between this two ways calling function. – user4003407 Jun 19 '19 at 20:54
  • You have to specify the parameter you want to send the data to. ex: `SCP-ImplementationFiles -selectedDirectory $directoryPrompt -fileName $rdfFile.Name` – spicy.dll Jun 20 '19 at 13:56

0 Answers0