{"id":8611,"date":"2012-07-25T00:01:00","date_gmt":"2012-07-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/07\/25\/an-introduction-to-powershell-remoting-part-three-interactive-and-fan-out-remoting\/"},"modified":"2012-07-25T00:01:00","modified_gmt":"2012-07-25T00:01:00","slug":"an-introduction-to-powershell-remoting-part-three-interactive-and-fan-out-remoting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/an-introduction-to-powershell-remoting-part-three-interactive-and-fan-out-remoting\/","title":{"rendered":"An Introduction to PowerShell Remoting Part Three: Interactive and Fan-Out Remoting"},"content":{"rendered":"<p class=\"CodeBlock\"><b>Summary<\/b>: Guest blogger, Jason Hofferle, talks about Windows PowerShell Interactive and fan-out remoting.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. TechReady&nbsp;15 in Seattle has been a great event. I am really enjoying getting to see friends. Of course, I am also really enjoying Jason&rsquo;s series about PowerShell Remoting. As a refresher here is a bit about Jason:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5684.JHofferle.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5684.JHofferle.jpg\" alt=\"Photo of Jason Hofferle\" title=\"Photo of Jason Hofferle\" \/><\/a><\/p>\n<p style=\"padding-left: 30px\">Jason Hofferle has been an IT professional since 1997. His experience includes enterprise desktop engineering for a Fortune 500 financial institution and Active Directory design for local governments and law enforcement. Jason currently works for the Defense Contract Management Agency, where he implements new technology such as virtual desktop infrastructure. He recently has been speaking about Windows PowerShell at <a href=\"http:\/\/www.sqlsaturday.com\/\" target=\"_blank\">SQL Saturday<\/a> and <a href=\"http:\/\/itprocamp.com\/\" target=\"_blank\">IT Pro Camp<\/a> events in Florida, and he frequently attends the <a href=\"http:\/\/powershellgroup.org\/tampa.fl\" target=\"_blank\">Tampa PowerShell User Group<\/a>.<\/p>\n<p style=\"padding-left: 30px\">Blog: <a href=\"http:\/\/www.hofferle.com\/\" target=\"_blank\">Force Multiplication through IT Automation<\/a><br \/> Twitter: @jhofferle<\/p>\n<p>In Part Two of this series, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/07\/24\/an-introduction-to-powershell-remoting-part-two-configuring-powershell-remoting.aspx\" target=\"_blank\">Configuring PowerShell Remoting<\/a>, I discussed how to configure PowerShell Remoting in your environment. Now we&rsquo;re going to take a look at how it can be used after it&rsquo;s up and running.<\/p>\n<p>There are two primary PowerShell Remoting usage paradigms for IT professionals: interactive and fan-out. Interactive remoting is used when I need to interact with a remote computer as if I was sitting directly in front of the system, logged into the console. Fan-out remoting is used when I have a single command or script that I want to run on a group of computers. It could be two systems, or two thousand systems. Whenever I need a command to efficiently execute on a large number of systems, fan-out is the way to go.<\/p>\n<p>To use interactive remoting, or one-to-one, I utilize the <b>Enter-PSSession<\/b> cmdlet with the <b>ComputerName<\/b> parameter. When my prompt changes to reflect the remote computer&rsquo;s name, I know that I&rsquo;m interacting with the remote system. This is great for performing actions that don&rsquo;t have built-in functionality for performing actions against remote systems, such as registering a dynamic link library (DLL) to correct an issue. When I&rsquo;m finished working on the remote computer, the <b>Exit-PSSession<\/b> cmdlet closes the session, and my prompt returns to the local operating system.<\/p>\n<p style=\"padding-left: 30px\">Enter-PSSession &ndash;ComputerName DC1<\/p>\n<p style=\"padding-left: 30px\">Set-Location C:\\Windows\\System32<\/p>\n<p style=\"padding-left: 30px\">Regsvr32.exe .\\capiprovider.dll \/s<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0537.Part3-1.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0537.Part3-1.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>When I want to use fan-out remoting, or one-to-many, I turn to the <b>Invoke-Command<\/b> cmdlet. This time I use a list of computer names for the <b>ComputerName<\/b> parameter, and I provide the command that I want them to run for the <b>ScriptBlock<\/b> parameter. Because the command executes on the remote computer, tasks such as searching and filtering the event log are performed locally, and only the information I want is sent over the network. When using <b>Invoke-Command<\/b>, each returned object has a <b>PSComputerName<\/b> parameter added, which enables me to determine which remote computer each object came from.<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command &ndash;ComputerName DC1,Win7,Win7-2 &ndash;ScriptBlock {Get-Service The*}<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3618.Part3-2.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3618.Part3-2.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Typing commands into a script block can be tedious and error prone when it&rsquo;s more than something simple. <b>Invoke-Command<\/b> has a <b>FilePath<\/b> parameter than can be used when an entire script needs to be executed remotely. Windows PowerShell takes the .ps1 file on the local computer, and converts it into a script block automatically.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8865.Part3-3.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8865.Part3-3.jpg\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p style=\"padding-left: 30px\">Invoke-Command &ndash;ComputerName DC1,Win7 &ndash;FilePath C:\\MyScript.ps1<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6242.Part3-4.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6242.Part3-4.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>PowerShell Remoting can also be used in conjunction with background jobs. The <b>AsJob<\/b> parameter of <b>Invoke-Command<\/b> allows a long-running PowerShell Remoting command to run in the background, freeing up the Windows PowerShell console for other tasks. When the job has completed, the results can be retrieved with the <b>Receive-Job<\/b> cmdlet.<\/p>\n<p style=\"padding-left: 30px\">Invoke-Command &ndash;ComputerName DC1,Win7 &ndash;ScriptBlock {Get-Service WinD*} &ndash;AsJob<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4544.Part3-5.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4544.Part3-5.jpg\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>PowerShell Remoting is extremely useful in situations where I need to quickly collect information from systems, like performing ad-hoc queries on event logs. During a recent deployment of Windows&nbsp;7, we experienced frequent issues with Outlook losing connectivity with Exchange. It was determined that a specific chip set combined with a particular driver on this particular operating system enabled a power-saving feature on the network adapter. Every time the monitor went into sleep mode, the adapter renegotiated the network speed to the lowest possible value. This disconnected the network for a few seconds, which was enough to cause Outlook to complain. Users would come back from a meeting and find that Outlook wasn&rsquo;t working correctly.<\/p>\n<p>After the fix was deployed to the Windows&nbsp;7 test group, we needed to prove that the issue had been resolved. I used PowerShell Remoting to collect network disconnection events from our Windows&nbsp;7 systems, exported the results to a comma separated values file, and then used Microsoft Excel to generate a chart showing how the disconnection events significantly dropped after the fix. In a few minutes, I was able to produce hard evidence that we resolved our remaining issue and get the green light for Windows&nbsp;7 deployment.<\/p>\n<p>~Jason<\/p>\n<p>Way cool stuff, Jason. Thank you for taking the time to share with us today. We look forward to Part Four tomorrow.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Guest blogger, Jason Hofferle, talks about Windows PowerShell Interactive and fan-out remoting. Microsoft Scripting Guy, Ed Wilson, is here. TechReady&nbsp;15 in Seattle has been a great event. I am really enjoying getting to see friends. Of course, I am also really enjoying Jason&rsquo;s series about PowerShell Remoting. As a refresher here is a bit [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,355,57,3,4,45],"class_list":["post-8611","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-jason-hofferle","tag-remoting","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Guest blogger, Jason Hofferle, talks about Windows PowerShell Interactive and fan-out remoting. Microsoft Scripting Guy, Ed Wilson, is here. TechReady&nbsp;15 in Seattle has been a great event. I am really enjoying getting to see friends. Of course, I am also really enjoying Jason&rsquo;s series about PowerShell Remoting. As a refresher here is a bit [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/8611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=8611"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/8611\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=8611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=8611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=8611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}