【问题标题】:Export Powershell output to user desktop (User desktop varies)将 Powershell 输出导出到用户桌面(用户桌面不同)
【发布时间】:2015-12-12 07:57:43
【问题描述】:

我正在运行一个 powershell 以将 Exchange 在线用户数据导出到一个 TXT 文件中,其中我提到了 C:\Users\%userprofile%\Desktop\Getdata.txt 作为一个位置,但是这个脚本在我们有不同用户的不同计算机上运行,​​所以我想将数据导出到桌面直接访问用户

脚本就是这样

Start-Transcript
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session 
get-mailbox |FT >C:\Users\%userprofile%\Desktop\Getdata.txt
Stop-Transcrip

我仍然无法将数据导出到桌面。我无法直接在C:\ 上导出数据,因为用户没有任何本地磁盘的权限。这是否可以在获取邮箱之前保持 powershell 完好无损。

【问题讨论】:

    标签: powershell exchange-server powershell-2.0


    【解决方案1】:

    如果您正在寻找当前用户的桌面路径,您可以通过以下方式获得:

    [environment]::GetFolderPath('Desktop')
    

    所以对于你的代码:

    |FT > (join-path ([environment]::GetFolderPath('Desktop')) "GetData.txt")
    

    【讨论】:

    • 所以会是这样吗? $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session get-mailbox |FT >[environment]::GetFolderPath('桌面')
    • 这会将命令的输出重定向到文件夹,但您还需要指定文件名。
    • 我收到一个错误:加入路径:找不到接受参数“GetData.txt”的位置参数。在 line:1 char:20 + get-mailbox |FL > (join-path [environment]::GetFolderPath('Desktop') "GetData.tx ... + ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Join-Path], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.JoinPathCommand
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 2022-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    相关资源
    最近更新 更多