Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

ps1 error: Object reference not set to an instance of an object.

$
0
0

Dear All!

Could you please help me? I got this error message when I ran my .ps1 file with a standard user's account.

Error message:
Exception calling "ReleaseComObject" with "1" argument(s)
: "Object reference not set to an instance of an object."
At C:\Windows\system32\Tasks\NYP\PSTbackup.ps1:4 char:74
+ $ret=[System.Runtime.Interopservices.Marshal]
::ReleaseComObject <<<< ($comobject)
+ CategoryInfo : NotSpecified: (:) [], Meth
odInvocationException
+ FullyQualifiedErrorId : DotNetMethodException



This .ps1 file can save all active .pst files in Outlook to a specified location.

PSTbackup.ps1:
function ReleaseComObject($comobject){
$ret=1
do{
$ret=[System.Runtime.Interopservices.Marshal]::ReleaseComObject($comobject)
}while($ret -ne 0)
}

$Outlook = New-Object -ComObject Outlook.Application
$stores = $Outlook.Session.Stores
$paths=$stores | Where-Object { $_.FilePath -like '*.pst' } | %{$_.FilePath}
ReleaseComObject $stores
$outlook.Quit()
ReleaseComObject $outlook
while(get-process outlook -ea silentlycontinue){sleep 5}
# now copy file(s).
$target="\\server\$env:username"
$paths|%{Copy-Item $_ $target}


Thanks in advance! :)
Regards,
iDrew


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>