2014-06-05 2 views
1

Outlook에서 PST 파일을 연결 해제하는 스크립트를 작성하려고합니다.Powershell을 사용하여 Outlook에서 PST 파일을 분리하는 방법은 무엇입니까?

나는 이런 식으로 뭔가에 노력했습니다 :

다음과 같은 오류
$Outlook = new-object -com outlook.application 
$Namespace = $Outlook.getNamespace("MAPI") 

$PSTtoDelete = "c:\test\pst.pst" 

$Namespace.RemoveStore($PSTtoDelete) 

내가 얻을 : 나는이와 다른 솔루션을 시도

"Cannot Find overload for "RemoveStore" and the argument count "1".

이 (여기 http://www.mikepfeiffer.net/2013/04/how-to-test-outlook-pst-personal-folder-file-access-with-powershell/을 발견) :

$namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$namespace,($PSTFolder)) 

은 내가 technect documentations에보고했다 내가 이해하는 경우 제대로 RemoveStore 메서드는 폴더를 필요로합니다.

누구든지 나에게이 점에 대한 힌트를 줄 수 있다면 크게 감사 할 것입니다.

감사합니다.

답변

2

는 링크에 따르면 스크립트는 첨부 된 PST의 이름가 아닌 경로를 기대하고있다. 이 시도 :

$Outlook = new-object -com outlook.application 
$Namespace = $Outlook.getNamespace("MAPI") 

$PSTtoDelete = "c:\test\pst.pst" 
$PST = $namespace.Stores | ? {$_.FilePath -eq $PSTtoDelete} 
$PSTRoot = $PST.GetRootFolder() 


$PSTFolder = $namespace.Folders.Item($PSTRoot.Name) 
$namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$namespace,($PSTFolder)) 
+0

덕분에 많이 :) 그것은 바로 일! – xashcorex

+0

PST의 주 계정 이름이 같으면 $ PSTFolder가 잘못된 개체입니다. RemoveStore가 작동하지 않습니다. – Alban

+0

RemoveStore는 이름 (문자열)을 기대하지 않습니다. Store 개체의 인스턴스가 필요합니다. –

1

이 모든 .PST 파일을 제거하려면 :

$Outlook = New-Object -ComObject Outlook.Application 
$Namespace = $Outlook.getNamespace("MAPI") 

$all_psts = $Namespace.Stores | Where-Object {($_.ExchangeStoreType -eq '3') -and ($_.FilePath -like '*.pst') -and ($_.IsDataFileStore -eq $true)} 

ForEach ($pst in $all_psts){ 
    $Outlook.Session.RemoveStore($pst.GetRootFolder()) 
} 
관련 문제