サンプルコードは問題ないようです。したがって、根本的な問題を何らかの方法で掘り下げる必要があります。スクリプトのタイプミスの可能性を排除しましょう。Set-Strictmode -Version 2.0
まず、スクリプトの先頭に必ず入れてください。これは、スペルミスのある変数名を見つけるのに役立ちます。そのようです、
# Test.ps1
set-strictmode -version 2.0 # Comment this line and no error will be reported.
$foo = "bar"
set-content -path ./test.txt -value $fo # Error! Should be "$foo"
PS C:\temp> .\test.ps1
The variable '$fo' cannot be retrieved because it has not been set.
At C:\temp\test.ps1:3 char:40
+ set-content -path ./test.txt -value $fo <<<<
+ CategoryInfo : InvalidOperation: (fo:Token) [], RuntimeException
+ FullyQualifiedErrorId : VariableIsUndefined
疑問符に関する次の部分は、Unicode に問題があるように思えます。Powershell でファイルを入力すると、次のように出力されます。
$file = "\\server\share\file.txt"
cat $file