Posts

Scan your network with PowerShell

Image
 I recently came across this cool script on LinkedIn that let you scan your network for devices with open ports. This is normally something that requires 3. party tool software that you might not be keen to install in your server. With this tool you can scan your network with a PowerShell script. How to run this Script Copy the script below to PowerShell ISE or save it as a script. Change the $localIP variable to your own IP address and your are ready to go. Clear # if you dont specify IP Address here, the script will get automatically address from network card with DHCP attribute $localIP = '192.168.1.10' # Obtain the IP address of the local machine if($localIP -eq '') {      $localIP = (Get-NetIPAddress | Where-Object { $_.AddressFamily -eq 'IPv4' -and $_.PrefixOrigin -eq 'Dhcp' }).IPAddress } # List of common ports to be scanned $portsToScan = @(20,21,22,23,25,53,80,110,123,143,161,443,445,993,995,3306,3389,5900,8080) # Extract the first three bytes

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").

PowerShell 7.2 is now available for Download

Image
 Great news, PowerShell 7.2 is now avilable for public download. Get PowerShell 7.2 here What is new with PowerShell 7.2 With PowerShell 7.2 there is integration with Microsoft Update, meaning that you installation of PowerShell in the future will be updated via Windows Update with new critical bug fixes or security updates. Enhanced ANSI support PowerShell 7.2 now has Enhanced ANSI support. With ANSI escape sequences, an industry standard way to provide text decoration support between console and a supported terminal. Use of these decorations is a way for commend-line tools and shells to highlight or distinguish information. You might also want to check out the built-in variable called $PSStyle to make your own decoration for your scripts. More information about PowerShell 7.2

Hyper-V PowerShell Commands

Image
If you are running Hyper-V virtual machine you might find this post interesting. There is plenty of PowerShell Cmdlets for managing a Hyper-v environments. Hyper-V Cmdlets In this post I will cover some of the most simple Cmd-Lets you can use to manage your Hyper-V environments. Get-VM: Shows a list of Virtual machines running on your server, with current state and Uptime. Start-VM: Start a given Virtual machine from PowerShell. Stop-VM: Shutdown or turn off a selected VM Save-VM: Save the state of the virtual machine Checkpoint-VM: Creates a Checkpoint for a given VM that you can restore to, if something goes wrong.  Get-VMSnapshot: Get a list of snapshots for given VM. Get-VM In the example below we use Get-VM to get a list of all the Virtual machines running on this server and the current state of these machines: Start-VM In the example below I start the Virtual machine named "Windows 11: Stop-VM In the example below I stop the virtual machine named "Windows 11"

Download PowerShell 7.1

Image
Have you downloaded PowerShell version 7.1? If not I will tell you how you can do it. Windows 10 comes with PowerShell 5.1 and Windows 11 comes with a minor upgrade. If you want to get the power of PowerShell 11 you will have to download and install it your self. It is not a part of Windows Updates. Windows 10: Windows 11: Download PowerShell 7.1 To download PowerShell 7.1 go to the official page on docs.microsoft.com  The package is available in both x86 and x64 bit version and also in .msi package and as a .zip file. That this site you will find all the information you will about PowerShell 7.1 Installation of PowerShell 7.1 Installation is straightforward. Just click, next, next next and you are ready to go: Be aware that the built in PowerShell that comes with Windows still will be the default PowerShell version. To start PowerShell 7, just search after PowerShell 7 in the Windows Start menu.

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