如何连接到 SMB 共享并在不安装的情况下写入 Powershell 中的文件?
How to connect to an SMB share and write to a file in Powershell without mounting?
我已经阅读了 Python 中的文档 here. Oddly enough, I can't find anything mentioning how to simply connect to (not mount) an SMB share with PowerShell. I'm looking for the equivalent of this:
with smbclient.open_file(args.share, username=args.smbuser, password=args.smbpass, mode='w', encoding='utf-8-sig', newline='') as file:
file.write("stuff")
您可以使用 Windows' net
实用程序
net use \server /user:domain\username password
或者使用 SmbShare
模块中的 PowerShell cmdlet New-SmbMapping:
New-SmbMapping -RemotePath '\server' -Username "domain\username" -Password "password"
之后,您可以简单地使用 UNC 路径写入文件,例如 Out-File
"Your output" | Out-File "\server\path\myfile.txt"
我已经阅读了 Python 中的文档 here. Oddly enough, I can't find anything mentioning how to simply connect to (not mount) an SMB share with PowerShell. I'm looking for the equivalent of this:
with smbclient.open_file(args.share, username=args.smbuser, password=args.smbpass, mode='w', encoding='utf-8-sig', newline='') as file:
file.write("stuff")
您可以使用 Windows' net
实用程序
net use \server /user:domain\username password
或者使用 SmbShare
模块中的 PowerShell cmdlet New-SmbMapping:
New-SmbMapping -RemotePath '\server' -Username "domain\username" -Password "password"
之后,您可以简单地使用 UNC 路径写入文件,例如 Out-File
"Your output" | Out-File "\server\path\myfile.txt"