Contact

Subscribe via Email

Subscribe via RSS

Categories

Creative Commons Attribution 4.0 International License
© Rakhesh Sasidharan

Use PowerShell to ping a device and email you when it’s up

While rebooting our servers today as part of the monthly patch cycle, one of the servers took longer than usual to shutdown and restart. I didn’t want to waste time keeping an eye out on it so I whipped up a simple script that will first keep pinging the server (until it’s down), then keep pinging the server until it’s up, and finally send me an email when the server is reachable. Pretty straight-forward script, here it is with some commenting and extra bits tacked on:

In a corporate environment you do not need to specify the SMTP server as it’s automatically picked up from the $PSEmailServer variable.

If you specify an SMTP server that requires authentication though you can pass this via the -Credential switch to Send-MailMessage. I didn’t add that above coz I didn’t need it but while typing this post I realize that that’s something others might find of use. Especially if you are using a 3rd party SMTP server that requires authentication.

For more Send-MailMessage switches check out this TechNet page and blog post.

Further updates to this script will be at GitHub.

Reset your self-hosted WordPress password or disable Google Authenticator via phpMyAdmin

No posts for a long time since I am between countries. I got posted to a different branch of the firm I work with, so the past few weeks I have been busy relocating and setting up. Since the last week of March I am now in Dubai. A new place, a fresh start, yaay! Sadly, no blog posts so far as I don’t have time at work or after it. Hopefully that gets rectified soon as things start settling down. 

Today I tried logging in to this blog and it wouldn’t let me. Kept denying access because the username/ password/ Google Authenticator code was incorrect. I know the first two have to be correct because I save them using LastPass so there’s no way I could have forgotten. The last one too has to be correct because it’s automatically generated after all, but who knows, maybe the plugin’s disabled or broken in the past few weeks?

Since this is a self-hosted blog I the idea to use phpMyAdmin and look at the WordPress database. Perhaps I can reset my password from there or disable Google Authenticator? Turns out that’s easy to do. 

Step 1: Login to cPanel of your hosting provider and launch phpMyAdmin. 

Step 2: Click the Databases tab and select your database. 

Step 3: Go over to the wp_usermeta or wp_users table. The former is for Google Authenticator. The latter for password. The latter has a row for each user. Click the Edit link for the user you want, go to the user_pass field, and enter an MD5 hash of the password you want. (If you use DuckDuckGo you can simply type the word followed by md5 and it will give you the MD5 hash! Else try this link). 

In my case I didn’t mess with the password. I suspected Google Authenticator & simply wanted to disable that. So the first table was what I went after. This table has multiple rows. All user meta data belonging to a particular user will have the same user_id. Find the user you are interested in, note the user_id, then find the key called googleauthenticator_enabled.  If Google Authenticator is enabled for the user this will say enabled; change it to disabled and you are done. 

That’s all for now!