I've found this function that I use to get the full path to a file:
Function Get-Filename($initialDirectory="")
{
[System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”) | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialdirectory
# $OpenFileDialog.filter = "TXT (*.txt)| *.txt"
$OpenFileDialog.ShowHelp = $true
$OpenFileDialog.ShowDialog() | out-null
$OpenFileDialog.filename
return $filnavn
}
$InputFil = Get-FileName
$InputFil
$OurFilesData = Get-Content $InputFil -Encoding UTF8
I get this error message:
Get-Content : Cannot bind argument to parameter 'Path' because it is null.
At line:27 char:29
+ $OurFilesData = Get-Content $InputFil -Encoding UTF8
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentCommand
What I know / has tried:
- I'm running the code locally on my own machine
- $InputFil returns the correct full path and filename (example: C:\Temp\E-Drevet_KANALNAVNE.CSV)
- If it set the $InputFil variable manually ($InputFil = "C:\Temp\E-Drevet_KANALNAVNE.CSV") I don't get the same error
- Power Shell Version 5.1.19041.546
Why do I get this error when the input seems to be the same as when I manually set the $InputFil variable?
Get-Content -Path $InputFil?return $filnavn