open folder from Network with Powershell

会有一股神秘感。 提交于 2019-12-23 04:45:56

问题


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
}

回答1:


You don't need to map a network share to open a file on a network share:

Get-Content \\server\sharename\foo.txt

Works just fine as does using Test-Path on a UNC path e.g.

Test-Path \\server\sharename\foo.txt

Is there a reason you need to map the share to a local drive?



来源:https://stackoverflow.com/questions/7875769/open-folder-from-network-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!