尝试仅打开Outlook DefaultProfileName

时间:2014-07-07 10:08:34

标签: outlook

有人可以建议我如何在不破坏变量的情况下使用$ Outlook.Application.DefaultProfileName。

Add-Member:无法将参数绑定到参数' InputObject'因为它是null。 在C:\ FindOutlookPSTsMike.ps1:14 char:21 + $对象| Add-Member<<<< -MemberType NoteProperty -Name' ComputerName' -Value $ ComputerName     + CategoryInfo:InvalidData:(:) [Add-Member],ParameterBindingValidationException     + FullyQualifiedErrorId:ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCo    mmand

Add-Member:无法将参数绑定到参数' InputObject'因为它是null。 在C:\ FindOutlookPSTsMike.ps1:15 char:21 + $对象| Add-Member<<<< -MemberType NoteProperty -Name' UserName' -Value $ UserName     + CategoryInfo:InvalidData:(:) [Add-Member],ParameterBindingValidationException     + FullyQualifiedErrorId:ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCo    mmand

Export-Csv:无法将参数绑定到参数' InputObject'因为它是null。 在C:\ FindOutlookPSTsMike.ps1:16 char:21 + $对象| Export-Csv<<<< -NoTypeInformation \ UK-PR-EXMC02 \ PSTLOG \ $ UserName- $ ComputerName-OpenPSTs- $ Date.csv     + CategoryInfo:InvalidData :( :) [Export-Csv],ParameterBindingValidationException     + FullyQualifiedErrorId:ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCo    mmand


$Date = Get-Date -format d-M-yyyy
$UserName = $env:USERNAME
$ComputerName = $env:COMPUTERNAME

$Outlook = New-Object -comObject Outlook.Application
$Profile = $Outlook.Application.DefaultProfileName 

$Object = $Profile.Session.Stores | Where {$_.FilePath -like "*.PST"} | Select `
     @{Expression={$_.DisplayName}; Label="PST Name in Outlook"},`
     @{Expression={$_.FilePath}; Label="PST Location/FileName"},`
     @{Expression={$_.IsOpen}; Label="PST Open in Outlook"},`
     @{Expression={(Get-Item $_.FilePath).Length / 1KB}; Label="PST File Size (KB)"}
$Object | Add-Member -MemberType NoteProperty -Name 'ComputerName' -Value $ComputerName
$Object | Add-Member -MemberType NoteProperty -Name 'UserName' -Value $UserName
$Object | Export-Csv -NoTypeInformation \\<NetworkShareName>\$UserName-$ComputerName-OpenPSTs-$Date.csv

Start-Sleep 5
Get-Process | Where {$_.Name -like "Outlook*"} | Stop-Process

1 个答案:

答案 0 :(得分:0)

Application.DefaultProfileName返回一个字符串,其中包含配置文件的名称,而不是对象。您是否尝试枚举特定配置文件中的PST文件?