使用 Powershell 从网络打开文件夹
我想使用 Powershell 从共享文件夹中打开 txt.File。问题是,无论用户是否登录,它都必须运行。我正在寻找类似网络使用的东西。 程序还应检查 psDrive 是否存在。
如果我这样做可以吗?
new-psdrive -name Z -psprovider FileSystem -root \\vcs.view
它的工作原理是这样的: 我映射然后检查文件是否存在:
#mapping
try
{
new-psdrive -name Z -psprovider FileSystem -root $ShareFolder
}
catch
{
echo "WriteMessageTOAdmin ERROR!!"
exit
}
$folderPath = "Z:\users.txt"
if(!(test-Path -path $folderPath))
{
echo "WriteMessageTOAdmin ERROR!!"
exit
}
I would like to open a txt.File from a sharedFolder with Powershell. The problem is, that it has to run whether an user is logged on or not. I'm looking for something like net-use.
The Program should also check, whether the psDrive exists or not.
Is it possible if I do that like this?
new-psdrive -name Z -psprovider FileSystem -root \\vcs.view
It works like that:
I map and then I check whether the file exists:
#mapping
try
{
new-psdrive -name Z -psprovider FileSystem -root $ShareFolder
}
catch
{
echo "WriteMessageTOAdmin ERROR!!"
exit
}
$folderPath = "Z:\users.txt"
if(!(test-Path -path $folderPath))
{
echo "WriteMessageTOAdmin ERROR!!"
exit
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要映射网络共享即可打开网络共享上的文件:
与在 UNC 路径上使用
Test-Path
一样工作得很好,例如您是否需要将共享映射到本地驱动器?
You don't need to map a network share to open a file on a network share:
Works just fine as does using
Test-Path
on a UNC path e.g.Is there a reason you need to map the share to a local drive?