{"id":15,"date":"2018-05-15T11:00:00","date_gmt":"2018-05-15T11:00:00","guid":{"rendered":"http:\/\/nkascocom.nk\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/"},"modified":"2018-05-15T11:00:00","modified_gmt":"2018-05-15T11:00:00","slug":"2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell","status":"publish","type":"post","link":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/","title":{"rendered":"How to remotely force kill a Windows session with Powershell"},"content":{"rendered":"<div class=\"sqs-html-content\">\n<p>If you work in Ops support you often run into situations where you need to remotely log a user off their machine. Today I&#8217;m going to share my general go-to snippet for quickly doing this. To me, <strong>quser.exe<\/strong> does everything I need it to and and the <strong>logoff<\/strong> command handles the actual logoff once I know the user ID. So instead of reinventing the wheel, we can simply wrap that in a way that flows quickly:<\/p>\n<p>To start, we simply need to run quser.exe in an <em>Invoke-Command<\/em> scriptblock:<\/p>\n<pre>$Computer = Read-Host \"Enter a Computer name\"\n\nif(Test-Connection -ComputerName $Computer -Count 1 -Quiet){\n&nbsp;&nbsp;&nbsp; Invoke-Command -ComputerName $Computer -ScriptBlock {quser}\n\n&nbsp;&nbsp;&nbsp; $ID = Read-Host \"Enter ID of user to logoff\"\n\n&nbsp;&nbsp;&nbsp; Invoke-Command -ComputerName $Computer -ArgumentList $ID -ScriptBlock {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; param($ID)\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logoff $ID\n&nbsp;&nbsp;&nbsp; }\n} else{\n&nbsp;&nbsp;&nbsp; Write-Host \"$Computer appears to be offline.`n\"\n}\n\nRead-Host \"Press enter to exit\"<\/pre>\n<p>So as you can see here we&#8217;re just doing a quick ping check based on user input and then displaying the list of current sessions followed by prompting the user to input an ID to force logoff.&nbsp;<\/p>\n<p><em>Note: This may require elevation in your environment so be sure to launch the script as admin, or wrap it in a .lnk shortcut that auto launches as admin.<\/em><\/p>\n<p>That&#8217;s it! Quick and simple way to force users to logoff. What other sort of quick scripts do you run in your environment?&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p style=\"white-space: pre-wrap;\">If you work in Ops support you often run into situations where you need to remotely log a user off their machine. Today I&#8217;m going to share my general go-to snippet for quickly doing this. To me, <strong>quser.exe<\/strong> does everything I need it to and and the <strong>logoff<\/strong> command handles the actual logoff once I know the user ID. So instead of reinventing the wheel, we can simply wrap that in a way that flows quickly.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to remotely force kill a Windows session with Powershell - Nathan Kasco - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to remotely force kill a Windows session with Powershell - Nathan Kasco - Blog\" \/>\n<meta property=\"og:description\" content=\"If you work in Ops support you often run into situations where you need to remotely log a user off their machine. Today I&#039;m going to share my general go-to snippet for quickly doing this. To me, quser.exe does everything I need it to and and the logoff command handles the actual logoff once I know the user ID. So instead of reinventing the wheel, we can simply wrap that in a way that flows quickly.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Nathan Kasco - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-15T11:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nate Kasco\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Bu5yGiraffe\" \/>\n<meta name=\"twitter:site\" content=\"@Bu5yGiraffe\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nate Kasco\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/\"},\"author\":{\"name\":\"Nate Kasco\",\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3\"},\"headline\":\"How to remotely force kill a Windows session with Powershell\",\"datePublished\":\"2018-05-15T11:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/\"},\"wordCount\":194,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/\",\"url\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/\",\"name\":\"How to remotely force kill a Windows session with Powershell - Nathan Kasco - Blog\",\"isPartOf\":{\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/#website\"},\"datePublished\":\"2018-05-15T11:00:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.nkasco.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to remotely force kill a Windows session with Powershell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/#website\",\"url\":\"https:\/\/blog.nkasco.com\/wordpress\/\",\"name\":\"Nathan Kasco - Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.nkasco.com\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3\",\"name\":\"Nate Kasco\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png\",\"url\":\"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png\",\"contentUrl\":\"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png\",\"width\":200,\"height\":200,\"caption\":\"Nate Kasco\"},\"logo\":{\"@id\":\"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png\"},\"sameAs\":[\"http:\/\/nkascocom.nk\/wordpress\",\"https:\/\/x.com\/Bu5yGiraffe\"],\"url\":\"https:\/\/blog.nkasco.com\/wordpress\/index.php\/author\/nate\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to remotely force kill a Windows session with Powershell - Nathan Kasco - Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"How to remotely force kill a Windows session with Powershell - Nathan Kasco - Blog","og_description":"If you work in Ops support you often run into situations where you need to remotely log a user off their machine. Today I'm going to share my general go-to snippet for quickly doing this. To me, quser.exe does everything I need it to and and the logoff command handles the actual logoff once I know the user ID. So instead of reinventing the wheel, we can simply wrap that in a way that flows quickly.","og_url":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/","og_site_name":"Nathan Kasco - Blog","article_published_time":"2018-05-15T11:00:00+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo-1.png","type":"image\/png"}],"author":"Nate Kasco","twitter_card":"summary_large_image","twitter_creator":"@Bu5yGiraffe","twitter_site":"@Bu5yGiraffe","twitter_misc":{"Written by":"Nate Kasco","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#article","isPartOf":{"@id":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/"},"author":{"name":"Nate Kasco","@id":"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3"},"headline":"How to remotely force kill a Windows session with Powershell","datePublished":"2018-05-15T11:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/"},"wordCount":194,"commentCount":0,"publisher":{"@id":"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/","url":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/","name":"How to remotely force kill a Windows session with Powershell - Nathan Kasco - Blog","isPartOf":{"@id":"https:\/\/blog.nkasco.com\/wordpress\/#website"},"datePublished":"2018-05-15T11:00:00+00:00","breadcrumb":{"@id":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/2018\/05\/15\/2018-5-10-how-to-remotely-force-kill-a-windows-session-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.nkasco.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"How to remotely force kill a Windows session with Powershell"}]},{"@type":"WebSite","@id":"https:\/\/blog.nkasco.com\/wordpress\/#website","url":"https:\/\/blog.nkasco.com\/wordpress\/","name":"Nathan Kasco - Blog","description":"","publisher":{"@id":"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.nkasco.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/blog.nkasco.com\/wordpress\/#\/schema\/person\/1dfd694a2ed094a43a37dc6882c65eb3","name":"Nate Kasco","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png","url":"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png","contentUrl":"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png","width":200,"height":200,"caption":"Nate Kasco"},"logo":{"@id":"https:\/\/blog.nkasco.com\/wordpress\/wp-content\/uploads\/2024\/03\/cropped-logo.png"},"sameAs":["http:\/\/nkascocom.nk\/wordpress","https:\/\/x.com\/Bu5yGiraffe"],"url":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/author\/nate\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nkasco.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}