Posts

Showing posts with the label IP

Use ChatGPT to write PowerShell Scripts

Image
 Did you know that ChatGPT can help you to write PowerShell scripts? You properly have heard about ChatGPT, but did you knew that ChatGPT can help you write PowerShell scripts? Asking ChatGPT for a script to perform a simple task Let me show you a little example how you can ask ChatGPT for help creating a script: The result from ChatGTP: It is actually that simple. I have used PowerShell to help me with scripts that can do all kind of stuff. I have asked about scripts to pull out date from Active Directory and how to export Windows Firewall rules. It is not that I can't write the script myself, but it is much faster with ChatGPT. Often I use AI to write like the main idea for my script and then I make some small adjustments myself. Go ahead and see how fast and easy it is. 

Use PowerShell to Discover Network Switch and port number

Image
 If you are working with Networks, that I am, you can sometimes have trouble to find out what switch port a computer is connected to. That can be because of bad marking of a network socket or because a cable simply just disappear into a wall and you are not able to follow it all the way to the rack cabinet. Let me show you an easy way to discover not just port number, but also name of the switch and VLAN for the connection. You will have to run the script below as an administrator, in order for it to work. Script: # Is Module installed - install if not available. if (Get-Module -ListAvailable -Name PSDiscoveryProtocol) {   Import-Module PSDiscoveryProtocol } else {   Install-Module -Name PSDiscoveryProtocol -Force   Import-Module PSDiscoveryProtocol } $Packet = Invoke-DiscoveryProtocolCapture -Type LLDP Get-DiscoveryProtocolData -Packet $Packet Be aware that you will need to have a manage lager 3 switch,  for the LLDP protocol,  to collect these information. As you can see above the PC

How to get Public IP Using PowerShell

Image
How to Get My Public IP Address Using PowerShell If you want find your public IP address that are being logged when you communicate on the Internet you can use a website like: ipconfig.me   But what if you want to get it using a PowerShell script? That is in fact also possible by using the command: Invoke-WebRequest. PowerShell command to get your Public IP Address: (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content Or (Invoke-WebRequest -uri "https://techthatworks.net/publicIP.php").Content This one line command can be very useful if you need the public IP address of a server without a webbrowser installed. E.g. a mailserver where you need to find out what IP address your server is presenting for other mailservers on the Internet. If you want to use this command in a script that maybe write something to a logfile, you can put the IP adresse in a variable and use it inside your script. $MyPublicIP = (Invoke-WebRequest -uri "http://ifconfig.me/ip").

Popular posts from this blog

Use PowerShell to Discover Network Switch and port number

How to get Public IP Using PowerShell

Use ChatGPT to write PowerShell Scripts