This is really helpful Webster, thanks! While I'm at it, I want to add my personal thanks to the effort you put into creating then various Xen* dcoumentation scripts. I know a lot of places that would charge good money for that level of automation. The fact that you provide it as a free service is really remarkable, and just further justifies your continued recognition as a CTP.
- Sean On Tue, Apr 7, 2015 at 8:06 AM, Webster <webs...@carlwebster.com> wrote: > Tested my test code and here is the updated code snippet: > > > > Write-Verbose > "$(Get-Date): `t`t`tClosing excel for $($Group.Name)" > > > $excel.Workbooks.Close($false) > > $excel.Quit() > > > > FindWordDocumentEnd > > WriteWordLine 0 0 "" > > > > While( > [System.Runtime.Interopservices.Marshal]::ReleaseComObject($selectionXL)){} > > While( > [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Range)){} > > While( > [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Chart)){} > > While( > [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Worksheet)){} > > While( > [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)){} > > > > If(Test-Path > variable:excel) > > { > > > Remove-Variable -Name excel 4>$Null > > } > > > > #If the Excel.exe process > is still running for the user's sessionID, kill it > > $SessionID = (Get-Process > -PID $PID).SessionId > > (Get-Process 'Excel' -ea 0 > | ?{$_.sessionid -eq $Sessionid}) | Stop-Process 4>$Null > > > > Write-Verbose > "$(Get-Date): `t`t`tDeleting temp files $($TempFile)" > > Remove-Item $TempFile > *>$Null > > > > Thanks > > > > > > Webster > > > > *From:* listsad...@lists.myitforum.com [mailto: > listsad...@lists.myitforum.com] *On Behalf Of *Mark Stang > *Sent:* Tuesday, April 07, 2015 9:05 AM > > *To:* powershell@lists.myitforum.com > *Subject:* Re: [powershell] Working with Web Query Files > > > > After > > > > $xl.quit() > > > > run this until it returns a 0 > > > > [System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl) > > > > On Tue, Apr 7, 2015 at 9:32 AM, Webster <webs...@carlwebster.com> wrote: > > Formatting got killed. > > #If the Excel.exe process is still running for the user's sessionID, kill > it > > $SessionID = (Get-Process -PID $PID).SessionId > > (Get-Process 'Excel' -ea 0 | ?{$_.sessionid -eq $Sessionid}) | stop-process > > > Thanks > > > Webster > > > -----Original Message----- > > From: listsad...@lists.myitforum.com > > [mailto:listsad...@lists.myitforum.com] On Behalf Of Webster > > > Sent: Tuesday, April 07, 2015 8:31 AM > > To: powershell@lists.myitforum.com > > Subject: RE: [powershell] Working with Web Query Files > > > > To kill the Excel process: > > > > #If the Excel.exe process is still running for the user's sessionID, > kill it > > $SessionID = (Get-Process -PID $PID).SessionId (Get-Process 'Excel' -ea > 0 | > > ?{$_.sessionid -eq $Sessionid}) | stop-process > > > > Thanks > > > > > > Webster > > > > > -----Original Message----- > > > From: listsad...@lists.myitforum.com > > > [mailto:listsad...@lists.myitforum.com] On Behalf Of Webster > > > Sent: Tuesday, April 07, 2015 7:54 AM > > > To: powershell@lists.myitforum.com > > > Subject: RE: [powershell] Working with Web Query Files > > > > > > Answers in-line. > > > > > > Thanks > > > > > > > > > Webster > > > > > > > -----Original Message----- > > > > From: listsad...@lists.myitforum.com > > > > [mailto:listsad...@lists.myitforum.com] On Behalf Of Joshua > > > > Delaughter > > > > Sent: Monday, April 06, 2015 10:53 PM > > > > To: powershell@lists.myitforum.com > > > > Subject: Re: [powershell] Working with Web Query Files > > > > > > > > Could the last line possibly kill other Excel instances that might be > > running? > > > > > > It will kill every instance of Excel running in the user's session. > > > > > > > Does the Quit method in the second to last line not kill the process? > > > > > > Not every time. Which makes me realize that I forgot to implement some > > > code I had tested that looped through and killed all the Excel > > > processes. In my lab, I had 12 Delivery Groups and after processing > > > all 12 groups, I had 12 Excel processes running. I thought I had > copied my > > test code into my script. > > > Looks like I forgot to do that. > > > > > > > > Is there a way to get the PID for the particular instance of Excel > > > > that this snippet starts instead? > > > > > > Yep, shown in another reply. > > > > > > > > > > > Sent from my iPhone > > > > > > > > > On Apr 6, 2015, at 5:40 PM, Sean Martin <seanmarti...@gmail.com> > > > > wrote: > > > > > > > > > > Good afternoon, > > > > > > > > > > I've been working on a Powershell script to create/update Mail > > > > > Contacts in > > > > Exchange based on information stored in our SharePoint site. This > > > > may be trivial to some of you, but I thought I would share for those > > > > who are relatively new to Powershell such as myself. > > > > > > > > > > Saving the list from Sharepoint to a Web Query File (.IQY) allows > > > > > for the > > > > presentation of current data each time the file is opened. I had a > > > > hard time figuring out how to work with the file directly, and > > > > didn't have the option of running the script on our Sharepoint > > > > server or remotely against it, so I used the following to save the > content > > as a CSV. > > > > > > > > > > # Convert Web Query File to CSV > > > > > $xl = New-Object -C Excel.Application -vb:$false $xl.DisplayAlerts > > > > > = $False $iqy = $xl.Workbooks.Open('<path to IQY file'>) > > > > > $iqy.SaveAs('<Path for saved CSV file>', 6) > > > > > $iqy.Close($false) > > > > > $xl.Quit() > > > > > Get-Process Excel | kill > > > > > > > > > > I can't take credit for the above, but it did take some time track > > > > > it down so I > > > > thought sharing it might help someone else avoid the research time. > > > > > > > > > > - Sean > > > > > > > > > > > > ================================================ > > > Did you know you can also post and find answers on PowerShell in the > > > forums? > > > http://www.myitforum.com/forums/default.asp?catApp=1 > > > > > > > > ================================================ > > Did you know you can also post and find answers on PowerShell in the > > forums? > > http://www.myitforum.com/forums/default.asp?catApp=1 > > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > > > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > > ================================================ > Did you know you can also post and find answers on PowerShell in the > forums? > http://www.myitforum.com/forums/default.asp?catApp=1 > ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1