Reverse an IP using regex (to do a reverse DNS/PTR search) in Notepad++ and get the PTR records in bash

Search for this pattern: ((\d){1,3}+).((\d){1,3}+).((\d){1,3}+).((\d){1,3}+)

And replace it with this pattern: \7.\5.\3.\1

Then add .in-addr.arpa at the end of each IP address.

I don’t think the plus signs are necessary; that was probably from when I was trying to figure out why I was only getting the first one or two numbers of some octets. For whatever reason, the regex pattern creates seven (or is it eight?) groups, and the correct groups are 1, 3, 5, and 7.

Once the addresses are in a text file, this following command will query each record in DNS and output the results in a comma separated format.

while read p; do gzz="echo $p,"; kla="dig ptr $p +short"; eval $gzz `$kla`; done < input.txt

Connecting to Office 365 through PowerShell

One thing to note: I’m using the StoredCredential library (?) to create and store my login info. The -Credential $My365Cred flag pulls in that saved credential so I don’t have to retype my login details every time. If you don’t have that library, remove the Credential flag from the commands below. This also won’t work if Multi Factor Authentication is enabled.

This is using the new way to connect to Exchange Online. The old way was to import the PowerShell session like this:

$global:exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $My365Cred -Authentication "Basic" -AllowRedirection
Import-PSSession $exchangeSession

Connect to Exchange Online PowerShell without Basic Authentication


#MSOnline module for user management, AzureAD, etc.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Scope CurrentUser -Force
Install-Module -Name msonline -Scope CurrentUser
# For Exchange Online
# Link says to install with admin privileges. Could this be installed using the -Scope CurrentUser flag?
Install-Module PowerShellGet -Force
Install-Module –Name ExchangeOnlineManagement
Connect-MsolService -Credential $My365Cred
Connect-ExchangeOnline -Credential $My365Cred

Some of the new commands are slightly different, e.g. Get-EXOMailbox (instead of Get-Mailbox).

PowerShell creating JSON objects

For a single level object, I find this to work well (and it’s simple/easy to understand):


$Body = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Body.Add('searchString', $Search)
$JsonBody = ConvertTo-Json $Body

More lines can be added with the $Body.Add function. Also, both arguments can take a string with single quote marks; I happened to be using a variable in that example.
This creates a JSON object that looks like this:

{
"searchString": ""
}

Like I said, very simple. The indents don’t show up here, but you can see them in the PS console.

For multiple level or nested JSON, this is the only way I can find that works. It’s a bit less “clean” in my opinion, since it’s not using native PowerShell functions and objects, but it does the job.

$JsonBody = ConvertTo-Json -Depth 2 @{"contact" = @{"firstName" = $firstName; "lastName" = $lastName; "email" = $email}; "type" = "User"}

That gives you an object which looks like this:

{
"contact": {
"email": "dfsgklj@dfgsd.com",
"firstName": "JPake",
"lastName": "GBgfhmio"
},
"type": "User"
}

Then you can fire that off somewhere using Invoke-WebRequest or whatever suits your needs.

Reload a PowerShell script

I have a ton of scripts imported by my PS profile when I launch it. If I make changes to one of those scripts which contains functions, I can reload it without restarting PS by putting a dot before it:

. .\Scripts\Misc\RCAPIGetInfo.ps1

PowerShell split string within a custom object or array (?)

# Get all mobile devices which are allowed and their user display names contain “NAMPR”

$devices = Get-MobileDevice

$disab = $devices | where UserdisplayName -Like 'NAMPR*' | where DeviceAccessState -eq 'Allowed' | select Identity, DeviceId, whenChanged, whenCreated,FriendlyName

#$disab is a custom object:

# ($disab | Get-Member) Results in TypeName: Selected.System.Management.Automation.PSCustomObject

# To manipulate the values within the custom object, they have to be accessed as strings. Then any of the string functions can be used.

# ($disab.Identity | Get-Member) Results in TypeName: System.String

# Take the identity field (which shows the user’s actual name) and “split” up to the backslash character. Example string looks like John Smith\ExchangeActiveSyncDevices\iPhone§DT4A99OTNH3QVBIC29NG4RI9B0

foreach ($i in $disab) { $i.Identity = $i.Identity.Split("\")[0] }

# The result is that the Identity field now only says John Smith.

Apache Guacamole set up with docker

docker run --name some-guacd -d guacamole/guacd

create mysql container:
docker pull mysql/mysql-server:latest
docker run --name=mysql01 -d mysql/mysql-server:latest
get root password: docker logs mysql01
docker exec -it mysql01 mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'somenewrootpassword';

docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --mysql > initdb.sql
docker cp initdb.sql mysql01:/initdb.sql
docker exec -it mysql01 bash
mysql guacamole -uroot -p < initdb.sql (could combine this with the last command, instead of running bash)

Before doing the mysql stuff, the guacamole database has to be created, then create a MySQL user for Guacamole and assign it privileges to access the newly created database.

docker run --name guacamole --link some-guacd:guacd --link mysql01:mysql -e MYSQL_DATABASE=guacamole -e MYSQL_USER=guac -e MYSQL_PASSWORD=tastyburger -d -p 8080:8080 guacamole/guacamole

Create an email address on your Office 365 domain that forwards to an external address/domain

Create the mail contact from the Exchange control panel. I’m sure it can be done with PowerShell, but I didn’t try.

Then run this command to set an email address on your Office 365 domain and the external email address where the mail should be forwarded.

Set-MailContact “[name of your Mail Contact]” -EmailAddresses “SMTP:externalemail@gmail.com”,”smtp:internalalias@yourdomain.com”

Any email sent to internalalias@yourdomain.com will then be sent on to externalemail@gmail.com.

Clean install Windows 10 Pro on a machine that originally had Windows 10 Home

By default, when installing from USB, Windows setup will detect the Home key in the BIOS and won’t allow you to choose to install the Pro edition.

The easiest/best way is to change (or add) ei.cfg on your install media to show the edition screen regardless of whether the BIOS has an embedded product key. Create ei.cfg in the sources folder on the USB media with these contents:

[Channel]
_Default
[VL]
0

Otherwise, if the Home OS is already installed, choose to “upgrade Windows version” or “change product key” and enter the key VK7JG-NPHTM-C97JM-9MPGT-3V66T.

https://answers.microsoft.com/en-us/windows/forum/windows_10-windows_install/switch-between-digital-license-keys-from-windows/80fe0b29-0463-44d6-8758-c0f2cfc1bdb2

Create a free website or blog at WordPress.com.

Up ↑