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



我正在运行powershell将Exchange在线用户数据导出到TXT文件中,我已经提到C:Users%userprofile%DesktopGetdata.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%DesktopGetdata.txt
Stop-Transcrip

我仍然不能导出数据到桌面。由于用户对本地磁盘没有权限,无法直接导出C:上的数据。是否有可能保持powershell完好无损直到get-mailbox.

如果您正在寻找当前用户的Desktop路径,您可以使用:

[environment]::GetFolderPath('Desktop')

对于你的代码:

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

相关内容

最新更新