Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
In Windows environments, communication between PCs on different network types—such as one PC on a Private network and another on a Public network—can fail due to mismatched network categories. These categories (Public, Private, Domain) determine firewall rules and device discovery settings, impacting tasks like file sharing or remote access. For example, a PC on a Public network typically blocks incoming connections, preventing it from being discovered by a PC on a Private network. This article explores how to use the PowerShell command Set-NetConnectionProfile to adjust network categories and resolve these issues, complemented by firewall configurations. PowerShell is ideal for this task due to its automation capabilities and precise control over network settings. Prerequisites include running PowerShell as an administrator and knowing the network interface names (verifiable with Get-NetConnectionProfile). The topic is fully applicable to Windows network environments, with no adjustments needed.
Examples:
Scenario: PC1 is connected to a Wi-Fi network classified as Public, and PC2 is on a Private network. PC2 cannot ping or share files with PC1 due to Public network restrictions.
Solution: Change PC1’s Wi-Fi network to Private to allow discovery and communication.
Command:
Set-NetConnectionProfile -InterfaceAlias "Wi-Fi" -NetworkCategory Private
Explanation:
ping <PC2_IP_address>
Error Handling: If the interface name is incorrect, use Get-NetAdapter to list adapters. If the command fails due to permissions, ensure PowerShell is run as administrator.
Security Note: Revert to Public after use in untrusted networks with:
Set-NetConnectionProfile -InterfaceAlias "Wi-Fi" -NetworkCategory Public
Scenario: In a small office network, multiple PCs have mixed network categories (some Public, some Private), causing inconsistent communication for shared resources.
Solution: Set all active network connections to Private on each PC to ensure uniform settings.
Command:
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
Explanation:
Get-NetConnectionProfile
Test file sharing or remote desktop between PCs.
Error Handling: If some connections don’t change, check for Domain-authenticated networks, which cannot be modified manually. Use Get-NetConnectionProfile | Where-Object {$_.NetworkCategory -ne 'DomainAuthenticated'} to filter.
Security Note: Ensure the network is trusted before setting all connections to Private.
Scenario: After setting PC1’s network to Private, PC2 still cannot access shared files due to firewall restrictions.
Solution: Enable firewall rules for file and printer sharing to allow communication.
Command:
Enable-NetFirewallRule -DisplayGroup "File and Printer Sharing"
Explanation:
Get-NetFirewallRule -DisplayGroup "File and Printer Sharing" -Enabled True
Error Handling: If sharing still fails, ensure the “Network Discovery” firewall group is enabled:
Enable-NetFirewallRule -DisplayGroup "Network Discovery"
Security Note: Disable these rules after use in temporary setups:
Disable-NetFirewallRule -DisplayGroup "File and Printer Sharing"