{"id":10261,"date":"2006-06-15T17:10:00","date_gmt":"2006-06-15T17:10:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/06\/15\/teched-start-session-script\/"},"modified":"2019-02-18T13:21:41","modified_gmt":"2019-02-18T20:21:41","slug":"teched-start-session-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/teched-start-session-script\/","title":{"rendered":"TECHED: Start-Session Script"},"content":{"rendered":"<p>Before my TechEd sessions, I ran a Windows PowerShell script which used animated figures to inform the users how long it would be until the session would start.&nbsp; It threw out some wisecracks along the way to keep things light and maintain their attention.&nbsp;&nbsp;<\/p>\n<p>A number of people asked me to post the script in the blog.&nbsp; I&#8217;m a little reticent to do so as <\/p>\n<ol>\n<li>I threw the script together on the day before the session and then tweaked it right before the session so it is not a well thought out script.\n<li>I don&#8217;t really know how to program against the MSAgent Control and I&#8217;m pretty sure that I&#8217;m doing it incorrectly.&nbsp; I just created the dang thing and then started exploring and made a few lucky guesses.&nbsp; I notice that if I crank the Sleep time down, I get strange behavior so it clearly is not correct.&nbsp; <\/li>\n<\/ol>\n<p>I&#8217;m going to share it anyway because people asked for it and because there are some cool techniques you might want to know about.&nbsp; There are actually 2 scripts.&nbsp; Start-Session and Invoke-MSAgent<\/p>\n<p>I&#8217;ve included the content for both scripts below and have attached the Start-Session Script (blogging software doesn&#8217;t seem to let me attach 2 files &#8211; go figure!)<\/p>\n<p>Enjoy!<\/p>\n<p>Jeffrey Snover<br \/>Windows PowerShell Architect<\/p>\n<p><font face=\"Courier New\" size=\"2\">#########&nbsp; Start-Session.ps1 #########################<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">#PSMDTAG:Author:Jsnover<br \/>#PSMDTAG:Title:Start-Session<br \/>#PSMDTAG:Description:Sample script to start a session<br \/>#PSMDTAG:USE:Agent.Control<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">param( [DateTime]$StartTime, $SessionTitle=&#8221;Session&#8221;, $Speaker=&#8221;Jeffrey&#8221;) <\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">function Invoke-Display()<br \/>{<br \/>&nbsp;&nbsp;&nbsp; Invoke-MSAgent $Message -Character (Get-RandomElement $Characters) `<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -Size $CharacterSize `<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -MoveToX $Random.Next(500) -MoveToY $Random.Next(500) `<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -StartX&nbsp; $Random.Next(500) -StartY&nbsp; $Random.Next(500)<br \/>&nbsp;&nbsp;&nbsp; Start-Sleep $SleepTime<br \/>}<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">function Get-RandomElement($Array)<br \/>{<br \/>&nbsp;&nbsp; $Array[ $Random.Next( $Array.Count ) ]<br \/>}<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">$Sleeptime = 20<br \/>$CharacterSize = 250<br \/>$WiseCracks=(<br \/>&nbsp;&nbsp;&nbsp; &#8220;PowerShell Rocks baby&#8221;,<br \/>&nbsp;&nbsp;&nbsp; # I know that this is misspelled but it has to be to sound correct<br \/>&nbsp;&nbsp;&nbsp; &#8220;Hay Hay, My My, the CLI will never die&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;Powershell has a wicked pissa scripting language&#8221;,&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8220;Powershell is wicked easy to use&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;Powershell is like, ya know, wicked consistent&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;puke monkey guts&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;exchange uses powershell, so should you&#8221;,&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp; &#8220;fish heads, fish heads, rolly polly fish heads, fish heads, fish heads, eat them up yumm&#8221;,&#8221;Jeffrey likes questions, ask them&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;Powershell has direct support for WMI, ADO, ADSI, XML, COM, and .NET&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;Shut up or I&#8217;ll replace you with a 2 line Powershell script, , just joking&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;PowerShell goes to 11&#8221;,<br \/>&nbsp;&nbsp;&nbsp; &#8220;triple panic abort&#8221;<br \/>)<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\"># Leverages the .NET Random number generator<br \/>$Random=New-Object Random<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\"># Characters are found in .ACS files <br \/>$Path = $(Join-Path $env:windir &#8220;msagent\\chars\\*.acs&#8221;)<br \/><\/font><a href=\"mailto:$Characters=@(dir\"><font face=\"Courier New\" size=\"2\">$Characters=@(dir<\/font><\/a><font face=\"Courier New\" size=\"2\"> $Path | foreach {($_.Name.Split(&#8220;.&#8221;))[0]})<br \/>while ($True)<br \/>{<br \/>&nbsp;&nbsp;&nbsp; $till = $StartTime &#8211; [DateTime]::now<br \/>&nbsp;&nbsp;&nbsp; if ($till.TotalSeconds -le 0)<br \/>&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Now it is time to go so let&#8217;s get it going<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Message = &#8220;hay $Speaker, Start the session&#8221;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $SleepTime = 10<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $CharacterSize = 600<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ($true)<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Invoke-Display<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; }<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; $Message = &#8220;$SessionTitle will start in $($Till.Minutes) minutes and $($till.Seconds) seconds&#8221;<br \/>&nbsp;&nbsp;&nbsp; Invoke-Display<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; $Message = Get-RandomElement $WiseCracks <br \/>&nbsp;&nbsp;&nbsp; Invoke-Display<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">&nbsp;&nbsp;&nbsp; $Message = Get-RandomElement $WiseCracks<br \/>&nbsp;&nbsp;&nbsp; Invoke-Display<br \/>}<br \/><\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">#########&nbsp; Invoke-MSAgent.ps1 #########################<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">#PSMDTAG:Author:Jsnover<br \/>#PSMDTAG:Title:Invoke-MSAgent<br \/>#PSMDTAG:Description:Sample script to invoke the MSAGENT CONTROL<br \/><\/font><font face=\"Courier New\" size=\"2\">param($Messages=&#8221;Hello&#8221;, $size=250, $CharacterName=&#8221;Merlin&#8221;, $MoveToX=500, $MoveToY=500, $StartX=0, $StartY=0, $Async=$false)<br \/>$Random = New-Object System.Random<br \/>$CharacterFileName = Join-path $env:windir (&#8220;msagent\\chars\\{0}.acs&#8221; -f $CharacterName)<br \/>$AgentControl = New-Object -COMObject Agent.Control.2<br \/>$AgentControl.Connected=$True<br \/>[void]$AgentControl.Characters.Load($CharacterName, $CharacterFileName)<\/font><\/p>\n<p><font face=\"Courier New\" size=\"2\">$Character = $AgentControl.Characters.Item($CharacterName) <br \/>$AnimationNames = @($Character.AnimationNames)<br \/>$Character.width = $Character.height=$Size<br \/>$action = $Character.MoveTo($StartX,$StartY)<br \/>$action = $Character.Show()<br \/>$action = $Character.MoveTo($MoveToX,$MoveToY)<br \/>#$action = $Character.Play($AnimationNames[$Random.Next($AnimationNames.Count)])<br \/>Foreach ($Message in @($Messages))<br \/>{<br \/>&nbsp;&nbsp;&nbsp; $action = $Character.Speak($Message)<br \/>}<br \/>$action = $Character.Hide()<br \/>if (!$Async)<br \/>{<br \/>&nbsp;&nbsp; while ($Character.Visible)<br \/>&nbsp;&nbsp; {&nbsp; Start-Sleep -MilliSeconds 250<br \/>&nbsp;&nbsp; }<br \/>}<br \/>$Character = $Null<br \/>$AgentControl.Connected=$False<br \/>$AgentControl = $Null<\/font><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/MSDNBlogsFS\/prod.evol.blogs.msdn.com\/CommunityServer.Components.PostAttachments\/00\/00\/63\/28\/23\/start-session.ps1\">start-session.ps1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before my TechEd sessions, I ran a Windows PowerShell script which used animated figures to inform the users how long it would be until the session would start.&nbsp; It threw out some wisecracks along the way to keep things light and maintain their attention.&nbsp;&nbsp; A number of people asked me to post the script in [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31],"class_list":["post-10261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-typecom"],"acf":[],"blog_post_summary":"<p>Before my TechEd sessions, I ran a Windows PowerShell script which used animated figures to inform the users how long it would be until the session would start.&nbsp; It threw out some wisecracks along the way to keep things light and maintain their attention.&nbsp;&nbsp; A number of people asked me to post the script in [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=10261"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=10261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=10261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=10261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}