Tag: Powershell
Powershell command to find all DNS resolvers for all interfaces
by Brian on May.29, 2025, under Computer Stuff, General Info, Windows Info
This will find and return the DNS resolvers for all populated interfaces, excluding loopback:
Get-DNSClientServerAddress | Where-Object {($_.ServerAddresses -notlike "{}" -and $_.InterfaceAlias -notlike "Loopback*")}
Self-signed certificate that lasts 5 years
by Brian on Mar.02, 2022, under Computer Stuff, General Info, Windows Info
On modern Windows servers, you can create a self-signed certificate with powershell, using the new-selfsignedcertificate command. By default, this certificate will only last for 1 year before expiring. To create a certificate that lasts a little longer, fire up an admin powershell, and do this:
$fromtoday = get-date
$5years = $fromtoday.addyears(5)
new-selfsignedcertificate -dnsname mycertname.mydomainname.com -notafter $5years -certstorelocation cert:\localmachine\my
Find External NAT Address using powershell
by Brian on Dec.21, 2021, under Computer Stuff, Networking, Windows Info
Sometimes, you need to know the external NAT address, but you can’t take over the console of the computer.
So, fire up powershell in the background, and run this command:
(Invoke-WebRequest -UseBasicParsing ifconfig.me/ip).Content.Trim()
Find users connected to all network shares
by Brian on Dec.03, 2021, under Computer Stuff, Windows Info
Needed this to determine which DFS namespaces that users were connecting to.
Get-WmiObject Win32_ServerConnection -ComputerName SERVERNAME | Select-Object ShareName,UserName,ComputerName
Find and delete a file on ALL drives using powershell
by Brian on May.05, 2021, under Computer Stuff, Windows Info
In the example below, replace filename.txt with the file you’d like deleted. It will be removed from all drives.
get-psdrive -PSProvider filesystem | ForEach-Object { Get-Childitem -Path $_.Root -Filter filename.txt -recurse | Remove-Item -force}