2016-01-21 27 views
0

我有一个问题,试图用PowerShell输出文件,我可以将文件导出到计算机的本地驱动器,但是当我想将其导出到网络位置时,它不会让我。Out-file导出到网络位置powershell

我收到以下错误:

Access to the path '\\fmadt-prod-web5\e$\ftproot\customer\temp\SiteLists\Classic\Hosted1.txt' is denied. 
    + CategoryInfo   : OpenError: (:) [Out-File], UnauthorizedAccessException 
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand 

这是我使用的代码:

$list2 | Format-Table -a -Property "WebAppName", "Version", "State"| Out-File '\\fmadt-prod-web5\e$\ftproot\customer\temp\SiteLists\Classic\Hosted1.txt' -force 

是否有可能导出到一个网络位置?我正在使用的用户也具有对该位置的管理权限。

回答

1

不能使用UNC路径,但可以映射PSDrive到该位置,并使用这些,那么

New-PSDrive -Name dest -Root \\fmadt-prod-web5\e$\ftproot\customer\temp\SiteLists\Classic -PSProvider FileSystem 

| out-file dest:\Hosted1.txt 

,如果你使用的New-PSDrive-Credential参数需要使用备用凭证访问驱动器。

+0

我现在收到一个错误,根目录不存在或不是一个文件夹,我已经验证他们的位置是精确的是存在的。我正在使用网络和服务器上的服务器管理员的凭据。想法? – Brett

0

你当然可以输出到unc路径,我经常使用这些工作。这几乎看起来像你没有,或者你正在运行脚本的帐户,因为没有,有权访问该目录。

E $是指服务器上的管理员共享,尝试通过Windows共享实际共享该目录,或者使用相关服务器上管理员组中的帐户运行脚本。此外,我总是使用双引号的路径,因为那样你可以包括变量 - 习惯的力量:)