将 Powershell 输出导出到用户桌面(用户桌面各不相同)
Export Powershell output to user desktop (User desktop varies)
我是 运行 一个 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:\
上导出数据,因为用户没有任何本地 disks.Can 的权限,这可能会在获取邮箱之前保持 powershell 完好无损。
如果您正在寻找当前用户的桌面路径,您可以通过以下方式获得:
[environment]::GetFolderPath('Desktop')
因此对于您的代码:
|FT > (join-path ([environment]::GetFolderPath('Desktop')) "GetData.txt")
我是 运行 一个 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:\
上导出数据,因为用户没有任何本地 disks.Can 的权限,这可能会在获取邮箱之前保持 powershell 完好无损。
如果您正在寻找当前用户的桌面路径,您可以通过以下方式获得:
[environment]::GetFolderPath('Desktop')
因此对于您的代码:
|FT > (join-path ([environment]::GetFolderPath('Desktop')) "GetData.txt")