Dienstag, 18. Oktober 2016

P:\My : The term 'P:\My' is not recognized as the name of a cmdlet,...

Error

Calling following gives the below error message.
powershell P:\My Roaming Documents\create_db_patch_deployment_package.ps1
P:\My : The term 'P:\My' is not recognized as the name of a cmdlet,...

Solution

Use call
powershell -File "P:\My Roaming Documents\create_db_patch_deployment_package.ps1"

module '%~dp0' could not be loaded

Error

Calling following gives the below error message. %~dp0 on the Windows command prompt is the equivalent of the bash dirname $0
powershell %~dp0\create_db_patch_deployment_package.ps1
%~dp0\create_db_patch_deployment_package.ps1 : The module '%~dp0' could not be loaded. For more information, run 'Import-Module %~dp0'.

Solution

Use call
powershell -File "%~dp0\create_db_patch_deployment_package.ps1"

Montag, 17. Oktober 2016

Write files without byte order mark (BOM)

If you use Out-File with -Encoding utf8 you invariably get a file where the first three bytes mark the byte order. This can break the further processing of the file, e. g. SQL+ is incapable to cope with it... why does Oracle support UTF-8 anyway ;-).
To get arround this, you can use [System.IO.File]::WriteAllLines with the proper encoding, e.g.
$UTF8NoBomEncoding = New-Object System.Text.UTF8Encoding(
      $False,
      $True)
[System.IO.File]::WriteAllLines(
      $outputFilePath,
      $array,
      $UTF8NoBomEncoding)