Get-Content -Raw parameter error
The -Raw
parameter of Get-Content
was introduced in PS3.
To get file contents in one string there are several methods.
- The fastest method that works in any PS version:
$text = [IO.File]::ReadAllText('c:\path\file.ext')
- The 2 times slower method for PS3+:
$text = Get-Content 'c:\path\file.ext' -Raw
- The 100 times slower PS2-compatible alternative:
$text = Get-Content 'c:\path\file.ext' | Out-String
- The 30 times slower PS2-compatible alternative:
$text = Get-Content 'c:\path\file.ext' -ReadCount 1000 | Out-String
I've experienced this error in ps v 5 when the -path parameter wasn't actually a path.
Try adding Write-Host $_.fullname
above the line throwing the error to make sure $_.fullname
is actually what you think it is.
You're using PowerShell v2 or earlier. The parameter -Raw
was introduced with PowerShell v3. Either upgrade PowerShell or pipe the output of Get-Content
through Out-String
:
$query = Get-Content -Path $_.FullName | Out-String
You should also be able to run the files directly with sqlcmd
(i.e. without reading their content and passing that to the command):
$result = SQLCMD -S $FullDBServer -E -I -i $_.FullName -d $Database