Posts

Showing posts with the label PowerShell

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

How to Search EventLog Using PowerShell

Image
In this post I will show you some tips on how you can search your computers EventLog using PowerShell. This can be very powerful if you need to search for e.g. a specifik error in the EventLog.  Basic Get-EventLog command The basic command is like shown below. Get-EventLog -LogName System If you want to you can filter using the parameter -EntryType to see only e.g. Errors in the eventlog: Get-EventLog -LogName System -EntryType Error In order to only see the newest 10 error you can enter the command below: Get-EventLog -LogName System -EntryType Error -Newest 10 Run Get-EventLog on Remote computer In order to check the EventLog on a remote computer you will have to use the Invoke command as shown below: All you need to do is to replace localhost with the name of the remote computer, where you want to run the command. For more information about the PowerShell Get-EventLog cmd-let check out Microsoft docs

How to check if your computer have a TPM chip

Image
How to detect a TPM chip using PowerShell Microsoft have stated that a TPM chip will be a hardware requirement for running Windows 11 . To help you detect if your computer is compliant with that I would like to share a script for just that. Be aware that not just your computer need a TPM chip. It also has to be a version 2.0 chip. Get-Tpm command can help you detect if you have a TPM chip in your computer. In order to detect of your computers TPM chip is version 2.0 you can run the following command: Get-WMIObject -computer localhost -class Win32_Tpm -Namespace root\cimv2\Security\MicrosoftTpm  | select PsComputerName,SpecVersion,manufacturerVersion,manufactureridtxt | fl If the first command state that TPMPresent is False, you might want to check if it is because the chip has just been disabled in BIOS/UEFI. That was the case on my computer. Check the manual of your motherboard. It might not be called TPM in your BIOS/UEFI settings. Here is an example:  

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