使用 Powershell 从网络打开文件夹 [英] open folder from Network with Powershell
问题描述
我想用 Powershell 从共享文件夹中打开一个 txt.File.问题是,无论用户是否登录,它都必须运行.我正在寻找类似 net-use 的东西.该程序还应检查 psDrive 是否存在.
如果我这样做可以吗?
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
}
推荐答案
您无需映射网络共享即可在网络共享上打开文件:
You don't need to map a network share to open a file on a network share:
Get-Content \\server\sharename\foo.txt
Get-Content \\server\sharename\foo.txt
与在 UNC 路径上使用 Test-Path
一样正常工作,例如
Works just fine as does using Test-Path
on a UNC path e.g.
测试路径 \\server\sharename\foo.txt
Test-Path \\server\sharename\foo.txt
是否需要将共享映射到本地驱动器?
Is there a reason you need to map the share to a local drive?
这篇关于使用 Powershell 从网络打开文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!