将Powershell输出导出到用户桌面(用户桌面不同)

将Powershell输出导出到用户桌面(用户桌面不同),powershell,exchange-server,powershell-2.0,Powershell,Exchange Server,Powershell 2.0,我正在运行powershell以导出TXT文件中的Exchange online用户数据,我在其中提到了C:\Users\%userprofile%\Desktop\Getdata.TXT作为一个位置,但此脚本在不同的计算机上运行,我们有不同的用户,因此我想直接将数据导出到用户的桌面 剧本就是这样 Start-Transcript $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Micros

我正在运行powershell以导出TXT文件中的Exchange online用户数据,我在其中提到了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的完整性。

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

[environment]::GetFolderPath('Desktop')
因此,对于您的代码:

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

那么会是这样吗$UserCredential=Get Credential$Session=New PSSession-ConfigurationName Microsoft.Exchange-ConnectionUri-Credential$UserCredential-Authentication Basic-AllowDirection Import PSSession$Session Get mailbox | FT>[environment]::GetFolderPath'Desktop',将命令输出重定向到文件夹,但您还需要指定一个文件名。我遇到一个错误:连接路径:找不到接受参数“GetData.txt”的位置参数。第1行:字符:20+获取邮箱| FL>加入路径[环境]::GetFolderPath'Desktop'GetData.tx…+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~CategoryInfo:InvalidArgument::[Join Path],ParameterBindingException+FullyQualifiedErrorId:PositionParameterNotFound,Microsoft.PowerShell.Commands.JoinPathCommand