User Tools

Site Tools


software:microsoft:windows:powershell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
software:microsoft:windows:powershell [2020/08/24 16:57] superwizardsoftware:microsoft:windows:powershell [2023/09/30 16:32] (current) – [Change Network Location to Public or Private with PowerShell] superwizard
Line 1: Line 1:
 ====== PowerShell Commands ====== ====== PowerShell Commands ======
 +
 +====== Change Network Location to Public or Private with PowerShell ======
 +
 +
 +<WRAP center round box >
 +
 +2023-09-30
 +
 +
 +On Windows 10/11 and Windows Server 2022/2019/2016, you can manage network connection locations from PowerShell. Open the elevated PowerShell console. List Windows network interfaces and the network profiles applied to them:
 +
 +
 +
 +To change the network for the network adapter with index 8 to Private, run the command:
 +     Set-NetConnectionProfile -InterfaceIndex 8 -NetworkCategory Private
 +Check that the network profile has changed:
 +     Get-NetConnectionProfile -InterfaceIndex 8
 +
 +From <https://woshub.com/how-to-change-a-network-type-from-public-to-private-in-windows/> 
 +
 +
 +
 +</WRAP>
 +
 +
 +====== Backup SQL ======
 +
  
 <WRAP center round box > <WRAP center round box >
Line 9: Line 36:
  
     Get-NetworkStatistics | Format-Table > c:\temp\GNS.txt     Get-NetworkStatistics | Format-Table > c:\temp\GNS.txt
 +    
 +    Get-NetworkStatistics - netstat -bano with filtering
 +    This code borrows from Shay Levy's Get-NetworkStatistics function
 +
 +From <https://gallery.technet.microsoft.com/scriptcenter/Get-NetworkStatistics-66057d71> 
 +
  
 </WRAP> </WRAP>
Line 21: Line 54:
  
 1. Ping devices locally or remotely 1. Ping devices locally or remotely
-Test-NetConnection -ComputerName "Hostname or IP" +    Test-NetConnection -ComputerName "Hostname or IP" 
-The Test-NetConnection cmdlet offers a number of ways to test network connectivity on the LAN and WAN. Enter the command as typed above and the computer will essentially perform a ping to determine if network connectivity between the local device and the target computer or domain exists.+ 
 +    the command as typed above and the computer will essentially perform a ping to determine if network  
 2. Check connectivity based on port or service 2. Check connectivity based on port or service
-Test-NetConnection "Hostname" -Port # +    Test-NetConnection "Hostname" -Port # 
-Another feature of the Test-NetConnection cmdlet is the ability to test the connectivity between the local device and the target host by specifying a port number. This is extremely useful for testing services between devices and the ports they communicate on specifically.+ 
 +    Another feature of the Test-NetConnection cmdlet is the ability to test the connectivity  
 +    between the local  
 3. Trace route communications 3. Trace route communications
-Test-NetConnection "Hostname" -traceroute +    Test-NetConnection "Hostname" -traceroute 
-Performing a trace route to determine how many hops (or steps) a packet must go through to get from the source to its destination is an important tool, as it allows you to see where the transmission is going, and more important, whether it was successful. If it wasn't, trace route will indicate where the packet failed along the path. +
-SEE: IT pro's guide to saving time with PowerShell (free TechRepublic PDF)+
 4. Obtain IP configuration details 4. Obtain IP configuration details
-Get-NetIPConfiguration +    Get-NetIPConfiguration 
-Similar to the ipconfig command, the Get-NetIPConfiguration cmdlet provides a holistic view of the network configuration(s) set on the network adapters of a computer. IP, DNS, and Gateway addresses are displayed and sorted by adapter name.+ 
 +    Similar to the ipconfig command, the Get-NetIPConfiguration cmdlet provides a holistic  
 5. Perform DNS lookups 5. Perform DNS lookups
-Resolve-DnsName -Name "Hostname" +    Resolve-DnsName -Name "Hostname" 
-Arguably, the backbone of a network is the DNS service. Without it, users would be forced to know the IP addresses for all websites and services. And yet when connectivity issues arise, DNS is often the culprit after ruling out IP-related errors. By appending the "-server" switch, followed by a DNS server's IP address, IT can perform a DNS resolve request against a specific server to verify resolution is working properly. + 
-SEE: Windows administrator's PowerShell script kit (Tech Pro Research)+   By appending the "-server" switch, followed by a DNS server's IP address, IT can perform a DNS resolve 
 +   request against a specific server to verify resolution is working properly. 
 6. View current TCP connections 6. View current TCP connections
-Get-NetTCPConnection +    Get-NetTCPConnection 
-Just like netstat before it, the Get-NetTCPConnection cmdlet allows for viewing of the current TCP connections that have been made to/from a device, as well as open or listening connections. This helps you troubleshoot issues that pertain to IPs and ports, specifically those bound to certain network services.+ 
 +   Just like netstat before it,  
 7. View & Set DNS information 7. View & Set DNS information
-Get-DnsClient +    Get-DnsClient 
-Set-DnsClientServer Address +    Set-DnsClientServer Address 
-This cmdlet lets you check the DNS client information for a device. It will indicate what DNS server(s) are being used by the device to perform address resolutions as configured on multiple adapters. The Set-DnsClientServerAddress cmdlet allows for specified DNS servers to be added to the network configuration.+ 
 +    This cmdlet lets you check the DNS client information for a device.  
 +    It will indicate what DNS server(s) are being used by the device to perform address resolutions as 
 +    The Set-DnsClientServerAddress cmdlet allows for specified DNS servers to be added to the network  
 8. Flush DNS cache 8. Flush DNS cache
-Clear-DnsClientCache +    Clear-DnsClientCache
-The DNS cache helps keep often used DNS resolution records stored locally on a device, allowing it to read that record instead of performing a lookup every time a record is requested. This helps speed up the already fast resolution process. If stale records--or those that haven't been updated--are present, this could lead to poor network performance, denial of service, or security issues that seek to exploit incorrect records that point user requests to the wrong server/service. +
-9. Release and renew DHCP leases +
-Invoke-Command -ComputerName -ScriptBlock {ipconfig /release} +
-Invoke-Command -ComputerName -ScriptBlock {ipconfig /renew} +
-While PowerShell includes many cmdlets to manage network settings, there is no direct way to release/renew DHCP leases without referencing another cmdlet first, then piping the results to a second or third cmdlet to be able to modify the DHCP setting. However, by leveraging the Invoke-Command, you can remotely (or via script) perform a release and/or renew by calling upon the ipconfig command. +
-10. Disable and enable network adapters +
-Disable-NetAdapter -Name "Adapter Name" +
-Enable-NetAdapter -Name "Adapter Name" +
-Last but certainly not least is the cmdlet for disabling/enabling network adapters on a device. While not as fancy a method for troubleshooting network problems as the cmdlets listed above, as any IT professional will tell you, sometimes the only thing you have to do to resolve a network-based problem is turn it off and on again.+
  
-From <https://www.techrepublic.com/article/10-powershell-commands-for-network-troubleshooting/> +    The DNS cache helps keep often used DNS resolution records stored locally on a device, 
  
 +9. Release and renew DHCP leases
 +    Invoke-Command -ComputerName -ScriptBlock {ipconfig /release}
 +    Invoke-Command -ComputerName -ScriptBlock {ipconfig /renew}
  
 +    there is no direct way to release/renew DHCP leases without referencing another cmdlet first, then piping 
 +    
 +10. Disable and enable network adapters
 +    Disable-NetAdapter -Name "Adapter Name"
 +    Enable-NetAdapter -Name "Adapter Name"
  
 +
 +From <https://www.techrepublic.com/article/10-powershell-commands-for-network-troubleshooting/> 
 </WRAP> </WRAP>
  
software/microsoft/windows/powershell.1598288257.txt.gz · Last modified: 2020/08/24 16:57 by superwizard