文件路径周围的空格过多

Excessive whitespace around filepath

PS C:\> $pst_path = $outlook.Session.Stores | where { ($_.FilePath -like '*.PST') } | Select Filepath | format-table -hide
PS C:\> $pst_path

C:\Users\abelej\Documents\Outlook Files\My Outlook Data File(1).pst


PS C:\> _

我尝试使用 $pst_path.trim() 方法来 trim 前导和尾随 space,但没有成功。您可以看到变量包含的所有白色 space。当我使用 Copy-Item 时出现问题,它抱怨文件名超过 260 个字符的限制。

Format-* cmdlet 用于向用户显示格式化数据。如果您需要进一步处理您的数据,请不要使用它们。只需展开 FilePath 属性 即可:

$outlook.Session.Stores |
  where { $_.FilePath -like '*.PST' } |
  select <b>-Expand</b> FilePath