bạn sẽ tìm thấy trên Microsoft web site giải thích về các hành vi lạ của 'dấu ngoặc vuông' trong biểu thức PowerShell.
NHƯNG
Khi tôi chỉ cần viết như sau (không có dấu ngoặc) nó chỉ does't làm việc cho tôi:
Set-Content -LiteralPath "\\server\share\temp\test.txt" -Value "coucou"
nhưng (theo như bài báo của Microsoft) sau việc
Set-Content -Path "\\server\share\temp\test.txt" -Value "coucou"
set-content -path '\\server\share\temp\`[test`].txt' -Value "coucou"
Tôi đã cố giải quyết sự cố này bằng PowerShell Drive
New-PSDrive -Name u -PSProvider filesystem -Root "\\server\share"
Và nó thậm chí còn tồi tệ nhất
Set-Content : Impossible de trouver une partie du chemin d'accès '\\server\share\server\share\server\share\temp\test.txt'.
Au niveau de ligne : 1 Caractère : 12
+ set-content <<<< -literalpath "u:\temp\test.txt" -Value "coucou"
+ CategoryInfo : ObjectNotFound: (\\server\shar...e\temp\test.txt:String) [Set-Content], DirectoryNotFo
undException
+ FullyQualifiedErrorId : GetContentWriterDirectoryNotFoundError,Microsoft.PowerShell.Commands.SetContentCommand
Bật arround giải pháp 1: tôi giải quyết nó bằng cách sử:
net use u: \\server\share
set-content -literalpath "u:\temp\test.txt" -Value "coucou"
Và sau đó followwing làm việc
set-content -literalpath "u:\temp\[test].txt" -Value "coucou"
Bật arround giải pháp 2: using FileInfo
# Create the file
set-content -path '\\server\share\temp\`[test`].txt' -Value "coucou"
# Get a FileInfo
$fic = Get-Item '\\server\share\temp\`[test`].txt'
# Get a stream Writer
$sw = $fic.AppendText()
# Append what I need
$sw.WriteLine("test")
# Don't forget to close the stream writter
$sw.Close()
Tôi nghĩ rằng lời giải thích là trong -literalpath
UNC đang kém hỗ trợ
Thật kỳ lạ, nó sẽ hoạt động nhưng tôi có thể sao chép vấn đề của bạn cũng như – ProfessionalAmateur
Thú vị. Tôi không thể lặp lại điều này. – zdan
Tôi tò mò - tại sao sử dụng công tắc -LiteralPath yêu cầu? – Goyuix