<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=AD_Scripts</id>
	<title>AD Scripts - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=AD_Scripts"/>
	<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=AD_Scripts&amp;action=history"/>
	<updated>2026-04-05T19:35:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=AD_Scripts&amp;diff=5324&amp;oldid=prev</id>
		<title>Busk at 03:20, 12 July 2024</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=AD_Scripts&amp;diff=5324&amp;oldid=prev"/>
		<updated>2024-07-12T03:20:54Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:20, 12 July 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l32&quot; &gt;Line 32:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 32:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Find Processes by User&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Find Processes by User&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;```&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;```&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Define the username to &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;log out &lt;/del&gt;and domain (adjust these values accordingly)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Define the username to &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;check for running processes &lt;/ins&gt;and domain (adjust these values accordingly)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;userToLogoff &lt;/del&gt;= &amp;quot;username&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;userToCheck &lt;/ins&gt;= &amp;quot;username&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$domain = &amp;quot;DOMAIN&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;$domain = &amp;quot;DOMAIN&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l46&quot; &gt;Line 46:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 46:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     # Use Invoke-Command to run commands remotely on each host&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     # Use Invoke-Command to run commands remotely on each host&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     Invoke-Command -ComputerName $host -ScriptBlock {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     Invoke-Command -ComputerName $host -ScriptBlock {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         # &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Find the session ID of &lt;/del&gt;the user&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;'s session using quser&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         # &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Get all processes and filter by &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;specified &lt;/ins&gt;user&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         $&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;sessions &lt;/del&gt;= &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;quser /server:$using:host &lt;/del&gt;| Where-Object { $_ -&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;match &lt;/del&gt;$using:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;userToLogoff &lt;/del&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         $&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;processes &lt;/ins&gt;= &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Get-WmiObject Win32_Process &lt;/ins&gt;| Where-Object { $_&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;.GetOwner().User &lt;/ins&gt;-&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;eq &lt;/ins&gt;$using:&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;userToCheck &lt;/ins&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         foreach ($&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;session &lt;/del&gt;in $&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;sessions&lt;/del&gt;) {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         foreach ($&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;process &lt;/ins&gt;in $&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;processes&lt;/ins&gt;) {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             # &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Extract &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;session &lt;/del&gt;ID&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             # &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Output &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;process name and &lt;/ins&gt;ID&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             $&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;sessionId = &lt;/del&gt;($&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;session -split '\s+'&lt;/del&gt;)&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;[2]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Write-Output &amp;quot;Process &lt;/ins&gt;$($&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;process.Name&lt;/ins&gt;) &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;with ID $&lt;/ins&gt;($&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;process.ProcessId&lt;/ins&gt;) &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;is running under user &lt;/ins&gt;$using:&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;userToCheck &lt;/ins&gt;on $using:host&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;            if &lt;/del&gt;($&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;sessionId -ne &amp;quot;SESSIONNAME&amp;quot;&lt;/del&gt;) &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;{&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;                # Log off the session&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;                logoff $sessionId /server:$using:host&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;                Write-Output &amp;quot;Logged off $(&lt;/del&gt;$using:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;userToLogoff) from session $sessionId &lt;/del&gt;on $using:host&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;            }&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         }&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     } -Credential &amp;quot;$domain\$&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;userToLogoff&lt;/del&gt;&amp;quot; -ErrorAction SilentlyContinue&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     } -Credential &amp;quot;$domain\$&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;userToCheck&lt;/ins&gt;&amp;quot; -ErrorAction SilentlyContinue&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;```&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;```&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Busk</name></author>
	</entry>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=AD_Scripts&amp;diff=5323&amp;oldid=prev</id>
		<title>Busk: Created page with &quot;# Remove Sessions by User ``` # Define the username to log out and domain (adjust these values accordingly) $userToLogoff = &quot;username&quot; $domain = &quot;DOMAIN&quot;  # Ensure the Active...&quot;</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=AD_Scripts&amp;diff=5323&amp;oldid=prev"/>
		<updated>2024-07-12T03:17:16Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;# Remove Sessions by User ``` # Define the username to log out and domain (adjust these values accordingly) $userToLogoff = &amp;quot;username&amp;quot; $domain = &amp;quot;DOMAIN&amp;quot;  # Ensure the Active...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;# Remove Sessions by User&lt;br /&gt;
```&lt;br /&gt;
# Define the username to log out and domain (adjust these values accordingly)&lt;br /&gt;
$userToLogoff = &amp;quot;username&amp;quot;&lt;br /&gt;
$domain = &amp;quot;DOMAIN&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Ensure the Active Directory module is loaded&lt;br /&gt;
Import-Module ActiveDirectory&lt;br /&gt;
&lt;br /&gt;
# Get all computer objects from Active Directory&lt;br /&gt;
$hosts = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name&lt;br /&gt;
&lt;br /&gt;
# Loop through each host&lt;br /&gt;
foreach ($host in $hosts) {&lt;br /&gt;
    # Use Invoke-Command to run commands remotely on each host&lt;br /&gt;
    Invoke-Command -ComputerName $host -ScriptBlock {&lt;br /&gt;
        # Find the session ID of the user's session using quser&lt;br /&gt;
        $sessions = quser /server:$using:host | Where-Object { $_ -match $using:userToLogoff }&lt;br /&gt;
        foreach ($session in $sessions) {&lt;br /&gt;
            # Extract the session ID&lt;br /&gt;
            $sessionId = ($session -split '\s+')[2]&lt;br /&gt;
            if ($sessionId -ne &amp;quot;SESSIONNAME&amp;quot;) {&lt;br /&gt;
                # Log off the session&lt;br /&gt;
                logoff $sessionId /server:$using:host&lt;br /&gt;
                Write-Output &amp;quot;Logged off $($using:userToLogoff) from session $sessionId on $using:host&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    } -Credential &amp;quot;$domain\$userToLogoff&amp;quot; -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
# Find Processes by User&lt;br /&gt;
```&lt;br /&gt;
# Define the username to log out and domain (adjust these values accordingly)&lt;br /&gt;
$userToLogoff = &amp;quot;username&amp;quot;&lt;br /&gt;
$domain = &amp;quot;DOMAIN&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Ensure the Active Directory module is loaded&lt;br /&gt;
Import-Module ActiveDirectory&lt;br /&gt;
&lt;br /&gt;
# Get all computer objects from Active Directory&lt;br /&gt;
$hosts = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name&lt;br /&gt;
&lt;br /&gt;
# Loop through each host&lt;br /&gt;
foreach ($host in $hosts) {&lt;br /&gt;
    # Use Invoke-Command to run commands remotely on each host&lt;br /&gt;
    Invoke-Command -ComputerName $host -ScriptBlock {&lt;br /&gt;
        # Find the session ID of the user's session using quser&lt;br /&gt;
        $sessions = quser /server:$using:host | Where-Object { $_ -match $using:userToLogoff }&lt;br /&gt;
        foreach ($session in $sessions) {&lt;br /&gt;
            # Extract the session ID&lt;br /&gt;
            $sessionId = ($session -split '\s+')[2]&lt;br /&gt;
            if ($sessionId -ne &amp;quot;SESSIONNAME&amp;quot;) {&lt;br /&gt;
                # Log off the session&lt;br /&gt;
                logoff $sessionId /server:$using:host&lt;br /&gt;
                Write-Output &amp;quot;Logged off $($using:userToLogoff) from session $sessionId on $using:host&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    } -Credential &amp;quot;$domain\$userToLogoff&amp;quot; -ErrorAction SilentlyContinue&lt;br /&gt;
}&lt;br /&gt;
```&lt;/div&gt;</summary>
		<author><name>Busk</name></author>
	</entry>
</feed>