<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Windows | TekCookie</title>
	<atom:link href="https://tekcookie.com/category/windows/feed/" rel="self" type="application/rss+xml" />
	<link>https://tekcookie.com</link>
	<description>Everything about IT</description>
	<lastBuildDate>Wed, 24 Nov 2021 14:31:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/06/cropped-TekCookie-211.png?fit=32%2C17&#038;ssl=1</url>
	<title>Windows | TekCookie</title>
	<link>https://tekcookie.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">174510684</site>	<item>
		<title>Get Local Administrator Group Members From Remote Computers</title>
		<link>https://tekcookie.com/local-administrator-group-members-from-remote-computers/</link>
					<comments>https://tekcookie.com/local-administrator-group-members-from-remote-computers/#comments</comments>
		
		<dc:creator><![CDATA[jeffythampi]]></dc:creator>
		<pubDate>Sun, 27 Jun 2021 09:33:13 +0000</pubDate>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<guid isPermaLink="false">https://tekcookie.com/?p=3422</guid>

					<description><![CDATA[In this article, we will discuss how to get a consolidated list of local administrators group members from remote computers. We use powersell command-let invoke-command to execute the command in the remote systems. Invoke-Command is the most used command-let to execute scripts remotely. To use Invoke-Command, powershell remoting has to be enabled in the remote [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>In this article, we will discuss how to get a consolidated list of local administrators group members from remote computers.</p>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-5f24a1d4     "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							Summary of Article<br>						</div>
																<div class="uagb-toc__list-wrap">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#one-liner-to-fetch-local-administrator-group-details" class="uagb-toc-link__trigger">One liner to fetch local administrator group details</a><li class="uagb-toc__list"><a href="#script-to-fetch-the-local-administrator-group-details" class="uagb-toc-link__trigger">Script to fetch the local administrator group details</a></ol>					</div>
									</div>
				</div>
			


<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p>We use powersell command-let invoke-command to execute the command in the remote systems. Invoke-Command is the most used command-let to execute scripts remotely.</p>



<p>To use Invoke-Command, powershell remoting has to be enabled in the remote system. Group policy can be used to deploy this feature in the organization.</p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">One liner to fetch local administrator group details</h2>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Invoke-Command -ScriptBlock { Get-LocalGroupMember administrators } -ComputerName pc1, pc2, pc3 | select PSComputerName, Name, SID, PrincipalSource</code></pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Result:</p>



<div class="wp-block-group has-white-color has-text-color has-background is-layout-flow wp-block-group-is-layout-flow" style="background-color:#d5d5d5">
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<pre id="block-285fd92c-5223-4dec-99b0-497b5d7c3fe9" class="wp-block-preformatted wp-block-code block-editor-block-list__block wp-block is-selected"><code><span style="color:#13608c" class="has-inline-color">PSComputerName Name                 SID                                            PrincipalSource
 -------------- ----                 ---                                            ---------------
 pc1            pc1\Administrator    S-1-5-21-1644265705-1531034170-3899888674-500  Local          
 pc1            pc1\user             S-1-5-21-1644265705-1531034170-3899888674-1002 Local          
 pc2            pc2\Administrator    S-1-5-21-1644265705-1531034170-3899899674-500  Local          
 pc3            pc3\Administrator    S-1-5-21-1644265705-1531034170-3899875674-500  Local  </span></code></pre>



<p></p>
</div>
</div>
</div>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p></p>



<p>This one liner will connect to the respective computers mentioned in the ComputerName parameter and lists out the member details. The PrincipalSource shows whether the object belongs to local or domain. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: As the script will connect to the remote computers, we need to run it with a user account which has access to these machines.</p></blockquote>



<p>Get-LocalGroupMember command-let is part of Microsoft.PowerShell.LocalAccounts and was made available from the version Powershell 5.1.</p>



<p>Further details of al commands are documented at <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/?view=powershell-5.1" target="_blank" rel="noreferrer noopener">https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/?view=powershell-5.1</a></p>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Script to fetch the local administrator group details</h2>



<p>We will now wrap the above one liner to a function with the necessary checks to ensure that the computers are online by checking with a ping request.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell line-numbers">function Fetch-LocalAdminMembers
 {
     [CmdletBinding()]
     [Alias()]
     Param
     (
         [Parameter(Mandatory=$true)]
         [String[]]$Computers,
         [Parameter()]
         [pscredential]$Credential
     )
     begin
     {
         #Checking whether the systems are online
         #OnlineComputers variable will have all the computers which responded to ping
         $OnlineComputers = @()
         $Computers | ForEach-Object {
             if(Test-Connection $_ -Count 1 -ErrorAction SilentlyContinue) {
                 $OnlineComputers += $_
             }
         }

     }

     process
     {
         #If credentials are not passed, the script runs in current user context
         if($Credential -eq $null)
         {
             Invoke-Command -ScriptBlock {Get-LocalGroupMember administrators; Start-Sleep -Seconds 2} -ComputerName $OnlineComputers   | select PSComputerName, Name, SID, PrincipalSource
         }
         else
         {
             Invoke-Command -ScriptBlock {Get-LocalGroupMember administrators; Start-Sleep -Seconds 2} -ComputerName $OnlineComputers -Credential $Credential  | select PSComputerName, Name, SID, PrincipalSource
         }
     }

     end
     {
         $OnlineComputers = $Credential = $null
     }
 }
</code></pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Executing the function</p>



<p>Fetch-LocalAdminMembers -Computers pc1, pc2</p>



<p>Result:</p>



<div class="wp-block-group has-background is-layout-flow wp-block-group-is-layout-flow" style="background-color:#d5d5d5">
<pre class="wp-block-preformatted"><code><span style="color:#13608c" class="has-inline-color">PSComputerName Name                 SID                                            PrincipalSource
 -------------- ----                 ---                                            ---------------
 pc1           pc1\Administrator    S-1-5-21-1644265705-1531034170-3899888674-500  Local          
 pc1           pc1\user             S-1-5-21-1644265705-1531034170-3899888674-1002 Local          
 pc2           pc2\Administrator    S-1-5-21-1644265705-1531034170-3894649674-500  Local          
 pc2           pc2\user2            S-1-5-21-1644265705-1531034170-<code>3894649674</code>-1002 Local </span></code> </pre>
</div>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p>We can refine the script further for faster execution, If you can identify it, I highly recommend you to comment it with the code snippet. </p>



<p>This will be helpful for the readers and will make this more interactive.<mark class="annotation-text annotation-text-yoast" id="annotation-text-403cec01-8321-4572-8a73-ef18fa2383d0"></mark></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Hope you liked the article and thank you for reading</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://tekcookie.com/local-administrator-group-members-from-remote-computers/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3422</post-id>	</item>
		<item>
		<title>Windows Update Information On Remote Servers with Powershell</title>
		<link>https://tekcookie.com/windows-update-information/</link>
					<comments>https://tekcookie.com/windows-update-information/#respond</comments>
		
		<dc:creator><![CDATA[jeffythampi]]></dc:creator>
		<pubDate>Fri, 18 Jun 2021 13:20:28 +0000</pubDate>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows 10]]></category>
		<category><![CDATA[Windows Server 2016]]></category>
		<category><![CDATA[Windows update details]]></category>
		<category><![CDATA[Windows Update Information with Powershell]]></category>
		<guid isPermaLink="false">https://tekcookie.com/?p=3198</guid>

					<description><![CDATA[In this article we will see how to use powershell script to get update information of remote windows servers. Last Windows Update Information We use the com object Microsoft.Update.Session to get the update results. Below one liner will tell us the previous update search and the last update installation date. Output: LastSearchSuccessDate LastInstallationSuccessDate --------------------- --------------------------- [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>In this article we will see how to use powershell script to get update information of remote windows servers.</p>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-3d8d94d9     "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							Table Of Contents						</div>
																<div class="uagb-toc__list-wrap">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#last-windows-update-information" class="uagb-toc-link__trigger">Last Windows Update Information</a><li class="uagb-toc__list"><a href="#new-windows-update-count" class="uagb-toc-link__trigger">New Windows Update Count</a><li class="uagb-toc__list"><a href="#pending-operating-system-restart" class="uagb-toc-link__trigger">Pending Operating System Restart</a><li class="uagb-toc__list"><a href="#windows-update-status" class="uagb-toc-link__trigger">Windows Update Status</a></ol>					</div>
									</div>
				</div>
			


<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p></p>



<h2 class="wp-block-heading">Last Windows Update Information</h2>



<p>We use the com object Microsoft.Update.Session to get the update results.</p>



<p>Below one liner will tell us the previous update search and the last update installation date.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">(New-Object -com "Microsoft.Update.AutoUpdate").Results
</code></pre>



<p>Output:</p>



<pre class="wp-block-preformatted">LastSearchSuccessDate LastInstallationSuccessDate
--------------------- --------------------------- 
 6/17/2021 3:54:31 AM  6/16/2021 3:57:34 AM</pre>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">New Windows Update Count</h2>



<p>Furthermore, to get the number of updates which are yet to be installed.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsInstalled=0").Updates)

#This will give the number of updates yet to install.
$Updates.Title.count </code></pre>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Pending Operating System Restart</h2>



<p>Any pending restart because of previous update can be identified through the registry &#8220;HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired&#8221;</p>



<p>The entry will have a value &#8220;true&#8221; if the operating system is waiting for a restart which is needed to complete an update.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Windows Update Status</h2>



<p>Above codes can be combined to get following information about a computer. </p>



<ol class="wp-block-list"><li>LastSearchSuccessDate</li><li>LastInstallationSuccessDate</li><li>NewUpdateCount</li><li>PendingReboot</li></ol>



<p>We can now wrap the script with invoke-command to remote execute in multiple systems</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">function Get-WindowsUpdateInformation()
 {
     param
     (
         [Parameter()]
         [string[]]
         $ComputerName="localhost"
     )


     <code>$Results = Invoke-Command -ScriptBlock  {     </code>
         <code>$result = (New-Object -com "Microsoft.Update.AutoUpdate").Results     </code>
         <code>$UpdateSession = New-Object -ComObject Microsoft.Update.Session     </code>
         <code>$UpdateSearcher = $UpdateSession.CreateupdateSearcher()     </code>
         <code>$Updates = @($UpdateSearcher.Search("IsInstalled=0").Updates)     </code>
         <code>$PendingReboot = $false     </code>
    
         #Checking pending reboot
         <code>if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { $PendingReboot=$true }     </code>
   
         #Framing the result to a list
         <code>New-Object psobject -Property @{         </code>
              <code>LastSearchSuccessDate = $result.LastSearchSuccessDate         </code>
              <code>LastInstallationSuccessDate = $result.LastInstallationSuccessDate         </code>
              <code>NewUpdateCount = $Updates.Title.count         </code>
              <code>PendingReboot = $PendingReboot     </code>
         <code>} </code>
     <code>} -ComputerName $ComputerName </code>

     <code>$Results | Select-Object @{Name="ServerName"; Expression={$_.PSComputerName}}, LastSearchSuccessDate, LastInstallationSuccessDate, NewUpdateCount, PendingReboot</code>
 }
 </code></pre>



<p>Multiple server/computer names can be passed as an array to get the update information, or the server name can also be read from a text file and passed as parameter.</p>



<pre id="block-a18e501e-39e5-40fa-91ad-224e419f395c" class="wp-block-preformatted">Get-WindowsUpdateInformation -ComputerName testhost1, testhost2</pre>



<p>Output:</p>



<pre class="wp-block-preformatted">ServerName LastSearchSuccessDate LastInstallationSuccessDate NewUpdateCount PendingReboot
---------- --------------------- --------------------------- -------------- -------------
 testhost1  6/17/2021 5:31:12 PM  5/16/2021 2:56:21 PM                     1         False
 testhost2  6/16/2021 6:33:22 PM  5/21/2021 4:22:34 AM                     1         False</pre>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p>If you have some better ideas or know other ways of doing this, please comment it. It will be informative for me and for the readers.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Hope you liked this article and thank you for reading</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://tekcookie.com/windows-update-information/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3198</post-id>	</item>
		<item>
		<title>Install drivers in Windows using PowerShell</title>
		<link>https://tekcookie.com/auto-install-drivers-using-powershell/</link>
					<comments>https://tekcookie.com/auto-install-drivers-using-powershell/#respond</comments>
		
		<dc:creator><![CDATA[jeffythampi]]></dc:creator>
		<pubDate>Wed, 16 Dec 2020 18:22:09 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 10]]></category>
		<category><![CDATA[Windows Server 2016]]></category>
		<category><![CDATA[Install drivers with PowerShell]]></category>
		<guid isPermaLink="false">https://tekcookie.com/?p=1811</guid>

					<description><![CDATA[Installing drivers for windows is very time consuming when the driver package contain multiple devices/models files with all possible platform architecture(x86, x64, etc.). We can leverage the pnputil.exe tool to perform the installation fast and easy. Consider a scenario of a multiple drivers packed to an iso image. Below script will install all the required [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Installing drivers for windows is very time consuming when the driver package contain multiple devices/models files with all possible platform architecture(x86, x64, etc.).</p>



<p>We can leverage the pnputil.exe tool to perform the installation fast and easy.</p>



<p>Consider a scenario of a multiple drivers packed to an iso image. Below script will install all the required drivers.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell line-numbers"># Mount the driver iso image
Mount-DiskImage D:\Driver\drivers-windows.iso

# Get the mount point/drive letter, considering that the above one is the only disk mounted
$isoMount = (Get-DiskImage -DevicePath \\.\CDROM0  | Get-Volume).DriveLetter

# Find the inf files and install
Get-ChildItem "$($isoMount):\" -Recurse -Include *.inf | ForEach-Object {
     $_.FullName
     pnputil /add-driver $_.FullName /install 
}</code></pre>



<p>Running the script would update all the drivers which are meant for your system hardware.</p>



<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Hope you like this article and thank you for reading.</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://tekcookie.com/auto-install-drivers-using-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1811</post-id>	</item>
		<item>
		<title>Device driver information using PowerShell</title>
		<link>https://tekcookie.com/device-driver-information-using-powershell/</link>
					<comments>https://tekcookie.com/device-driver-information-using-powershell/#respond</comments>
		
		<dc:creator><![CDATA[jeffythampi]]></dc:creator>
		<pubDate>Tue, 01 Sep 2020 02:34:06 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Device Driver]]></category>
		<category><![CDATA[Driver Info PowerShell]]></category>
		<guid isPermaLink="false">https://tekcookie.com/?p=1575</guid>

					<description><![CDATA[In this article, we will see how to get windows device driver details using PowerShell. Finding driver information is necessary as information gathering prior to software or system upgrades. WMI class Win32_PnPSignedDriver is used to get the device driver information This would enumerate complete information in the local system. To get information from multiple systems, [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p></p>



<p>In this article, we will see how to get windows device driver details using PowerShell. Finding driver information is necessary as information gathering prior to software or system upgrades.</p>



<figure class="wp-block-image size-large is-resized"><img data-recalc-dims="1" fetchpriority="high" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/08/DeviceDriver.jpg?resize=337%2C383&#038;ssl=1" alt="" class="wp-image-2786" width="337" height="383" srcset="https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/08/DeviceDriver.jpg?w=403&amp;ssl=1 403w, https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/08/DeviceDriver.jpg?resize=264%2C300&amp;ssl=1 264w" sizes="(max-width: 337px) 100vw, 337px" /></figure>



<p>WMI class Win32_PnPSignedDriver is used to get the device driver information</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">#Fetch all properties
Get-CimObject Win32_PnPSignedDriver | fl *</code></pre>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-CimInstance Win32_PnPSignedDriver | `
    Select DeviceClass, DeviceID, DeviceName, InfName, DriverVersion, FriendlyName, IsSigned</code></pre>



<p>This would enumerate complete information in the local system.</p>



<p>To get information from multiple systems, the command has to be executed against the respective servers. The server names can be either fetched from active directory or from text file.</p>



<p>The code below will query for IBM SDDDSM driver information from a list of servers in a text file.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell line-numbers">$servers = Get-Content "D:\server.txt"

foreach($server in $servers)
{
  
    Get-CimInstance Win32_PnPSignedDriver -ComputerName $server -ErrorAction SilentlyContinue | `
        where {$_.devicename -like "*IBM SDDDSM*"} | `
        select PSComputerName, DeviceClass, DeviceID, DeviceName, InfName, DriverVersion, FriendlyName, IsSigned
    if($Error)
    {
        #Display error if any server fails
        $server + " Error"
        $Error.Clear()
    }
}</code></pre>



<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Hope this is helpful and thank you for reading.</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://tekcookie.com/device-driver-information-using-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1575</post-id>	</item>
		<item>
		<title>Windows Firewall Rule using PowerShell</title>
		<link>https://tekcookie.com/windows-firewall-rule/</link>
					<comments>https://tekcookie.com/windows-firewall-rule/#respond</comments>
		
		<dc:creator><![CDATA[jeffythampi]]></dc:creator>
		<pubDate>Mon, 20 Apr 2020 19:09:34 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Firewall Rule using PowerShell]]></category>
		<category><![CDATA[Windows Firewall Rule using PowerShell]]></category>
		<guid isPermaLink="false">https://tekcookie.com/?p=1045</guid>

					<description><![CDATA[A firewall is the primary defense against attack from the outside world or from inside. Firewall is used as data center firewall and perimeter firewall to protect the data and infrastructure of any organization. We also have firewall module in the client and server operating system which we use and this also has to be [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>A firewall is the primary defense against attack from the outside world or from inside. Firewall is used as data center firewall and perimeter firewall to protect the data and infrastructure of any organization. We also have firewall module in the client and server operating system which we use and this also has to be configured to make sure only the desired traffic goes through.</p>



<p>This article is to demonstrate how to set firewall rule in Windows Operating System using PowerShell.</p>



<p>Windows Firewall has three profiles:</p>



<ul class="wp-block-list"><li><strong>Domain Profile</strong>: Applies to networks where the host system can authenticate to a domain controller</li><li><strong>Private Profile</strong>: User assigned profile used to designate private or home networks</li><li><strong>Public Profile</strong>: Used to designate public networks, Wi-Fi hotspots etc.</li></ul>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<p>Requirement: Block web access to ADSL modem portal</p>



<p>The requirement is to block ADSL modem web portal for the user. For that we need to create an outbound firewall rule to the modem IP address to port 80 (i.e. to block http traffic)</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Step 1: Create a Firewall Rule</h3>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">New-NetFirewallRule -Name BlockModem_Rule -DisplayName BlockModem_Rule</code></pre>



<p>This will create a rule &#8220;BlockModem_Rule&#8221; in the inbound rules(default as we have not mentioned the direction)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://i0.wp.com/www.tekcookie.com/wp-content/uploads/2020/04/create.jpg?fit=640%2C58&amp;ssl=1" alt="" class="wp-image-1049" width="776" height="69"/></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Step 2: Set the direction </h3>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-NetFirewallRule -DisplayName BlockModem_Rule | Set-NetFirewallRule -Direction Outbound</code></pre>



<p>This will set the rule as outbound rule</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://i2.wp.com/www.tekcookie.com/wp-content/uploads/2020/04/outbound.jpg?fit=640%2C59&amp;ssl=1" alt="" class="wp-image-1050" width="767" height="71"/></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Step 3: Set destination IP address to the rule</h3>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-NetFirewallRule -DisplayName BlockModem_Rule | Set-NetFirewallRule -RemoteAddress 192.168.1.1</code></pre>



<figure class="wp-block-image size-large is-resized"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/04/destIP.jpg?resize=308%2C303&#038;ssl=1" alt="" class="wp-image-1053" width="308" height="303"/></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Step 4: Set protocol and destination port</h3>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-NetFirewallRule -DisplayName BlockModem_Rule | Set-NetFirewallRule -Protocol tcp -RemotePort 80</code></pre>



<figure class="wp-block-image size-large is-resized"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/04/destPort.jpg?resize=317%2C266&#038;ssl=1" alt="" class="wp-image-1054" width="317" height="266"/></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Step 5: Set the rule action to block the traffic</h3>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-NetFirewallRule -DisplayName BlockModem_Rule | Set-NetFirewallRule  -Action Block</code></pre>



<p>This will block the traffic which matches to the firewall rule &#8220;BlockModem_Rule&#8221;</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://i1.wp.com/www.tekcookie.com/wp-content/uploads/2020/04/rule_block.jpg?fit=640%2C59&amp;ssl=1" alt="" class="wp-image-1055" width="760" height="71"/><figcaption>The rule icon changed from GREEN tick to RED block</figcaption></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Result:</h3>



<p>After setting the firewall rule, we will not be able to browse the modem web portal @ http://192.168.1.1/</p>



<figure class="wp-block-image size-large is-resized"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/04/firewallblockresult.jpg?resize=549%2C556&#038;ssl=1" alt="" class="wp-image-1056" width="549" height="556"/></figure>



<hr class="wp-block-separator"/>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Firewall Rule in one line</h2>



<p>The same firewall rule as one-liner</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">New-NetFirewallRule -Name BlockModem_Rule -DisplayName BlockModem_Rule `
-Enabled True -Direction Outbound -Profile Any -Action Block `
-RemoteAddress 192.168.1.1 -Protocol tcp -RemotePort 80</code></pre>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Disable Firewall rule</h3>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-NetFirewallRule -DisplayName BlockModem_Rule | Set-NetFirewallRule -Enabled False</code></pre>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading">Delete Firewall rule</h3>



<p>Find and remove the firewall rule: <strong>BlockModem_Rule</strong></p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-NetFirewallRule -DisplayName BlockModem_Rule | Remove-NetFirewallRule</code></pre>



<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p><em>Thank you for reading this article. Hope this is helpful to you.</em></p></blockquote>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
]]></content:encoded>
					
					<wfw:commentRss>https://tekcookie.com/windows-firewall-rule/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1045</post-id>	</item>
	</channel>
</rss>
