Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Problem with script only works in ISE not in powershell command line

$
0
0

I have a script below that I am having some trouble with it seems to work in the ISE but not when I right click then hit run in powershell. I have tried using a runas statement before to run powershell in admin mode but that did not work either.

$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)
$a = $f.Items
$b = $a.Count

#you'll get a popup in outlook at this point where you pick the folder you want to scan
$f = $n.pickfolder()

[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = new-object Windows.Forms.Form

$objShell = new-object -com shell.application
$d=$objShell.BrowseForFolder(0,"Title",0,"c:\")
$c= $d.self
$path=$c.path

#now loop through them and grab the attachments for the last 30 days for selected folder then save
foreach ($item in $a)
    { foreach ($attach in $item.Attachments)
            {  if ($item.ReceivedTime -gt (get-date).AddDays(-30))
            {if ($attach.filename.contains("pdf")){ $attach.saveasfile((Join-Path $path $attach.filename))
            }  
   elseif  ($attach.filename.contains("docx"))
              { $attach.saveasfile((Join-Path $path $attach.filename))
            }   
        }
   }
}



Viewing all articles
Browse latest Browse all 21975

Trending Articles



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