<p>Wrote the following in PowersHell as a quick iTunes demonstration:</p>

<pre><code>$iTunes = New-Object -ComObject iTunes.Application
$LibrarySource = $iTunes.LibrarySource
foreach ($PList in $LibrarySource.Playlists)
{
  write-host $PList.name
}
</code></pre>

<p>This works well and pulls back a list of playlist names.
However on trying to close iTunes a warning appears</p>

<blockquote>
  <p>One or more applications are using the iTunes scripting interface. Are you sure you want to quit?</p>
</blockquote>

<p>Obviously I can just ignore the message and press [Quit] or just wait the 20 seconds or so, but is there a clean way to tell iTunes that I've finished working with it?</p>

<pre><code>Itunes 7.7.1, Windows XP
</code></pre>

[{'answer_id': 52309, 'author': 'bruceatk', 'author_id': 791, 'author_profile': 'https://Stackoverflow.com/users/791', 'pm_score': 3, 'selected': True, 'text': "<p>Here is one thing that I did on my a Powershell script that adds podcasts to iTunes. I use Juice on a server to download all the podcasts that I listen to.  The script uses .Net methods to release the COM objects.  When I wrote my iTunes script I had read a couple of articles that stated you should release your COM objects using .NET.</p>\n\n<pre><code>\n    [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$LibrarySource)\n    [void][System.Runtime.InteropServices.Marshal]::ReleaseComObject([System.__ComObject]$iTunes)\n</code></pre>\n\n<p>I also run my scripts the majority of time from a shortcut, not from the powershell prompt. </p>\n\n<p>Based on your comments, I did some testing and I determined that I would get the message when running against iTunes, if I ran my script in a way that leaves powershell running.  iTunes seems to keep track of that.  Running the script in a manner that exits it's process after running, eliminated the message.</p>\n\n<p>One method of running your script from powershell, is to prefix your script with powershell.</p>\n\n<pre><code>powershell .\\scriptname.ps1</code></pre>\n\n<p>The above command will launch your script and then exit the process that was used to run it, but still leaving you at the powershell prompt.</p>\n"}, {'answer_id': 54003, 'author': 'Steven Murawski', 'author_id': 1233, 'author_profile': 'https://Stackoverflow.com/users/1233', 'pm_score': 0, 'selected': False, 'text': '<p>You should be able to set $itunes to $null.  Alternatively, $itunes should have a quit method you can call.  $itunes.quit()</p>\n'}]
['https://Stackoverflow.com/questions/52286', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5330/']