Wednesday, November 01, 2017

Testing a URL is 200 OK

If you do work with load balances, checking that a URL is up (200 ok) is common, here is a simple use of powershell and wget to see if it is up. With proxy and with proxy.

wget ''  | % { "$($_.StatusCode) $($_.StatusDescription)" }

wget '' -proxy '' | % { "$($_.StatusCode) $($_.StatusDescription)" }

Tuesday, October 24, 2017

Control your Tesla Model S, X or 3 using PowerShell

Control your Tesla Model S, X or 3 using PowerShell .

I don't know if you should laugh or cry...

Connecting to Tesla

In order to retrieve data and send commands to a Tesla vehicle each time you open a new PowerShell session you first need to tet a token from the Tesla customer API OATH service and get the ID used by the API to identify the vehicle you wish to affect...

Wednesday, September 13, 2017

Recover a SQL Database that you dont have access to

If you don't have SQL access, but have local server Administrator access, do the following:

Open SQL Server Configuration Manager
  • Stop the SQL Server Instance you need to recover the SA password
  • Open the properties on the SQL Server Instance and click on the Advanced tab
  • Change the Startup parameter by adding -m; at the begging of the line and click OK
  • Start the SQL Service Instance
NOTE: exactly like this "-m;"

Open the command prompt
Run sqlcmd
Run the following command to add an existing account to the sysadmin server role.

EXEC sp_addsrvrolemember 'YourDomainName\YourUserName', 'sysadmin';

Make sure: SQL Browser service is running. Remove -m; after you have done and restart SQL

Works a charm !

Easy powershell function to resolve SIDs to SamAccountNames

Powershell function:

Function f-sid {
param ( [Parameter(Mandatory=$true)][String]$Sid)
$objSID = New-Object System.Security.Principal.SecurityIdentifier($Sid)
Try {
($objSID.Translate( [System.Security.Principal.NTAccount])).value
Catch {
Write-host “`nCouldn’t find any entry matching SID : $Sid” -foregroundcolor cyan

To use it:

> f-sid [yourSID]

if you have a list of SIDs in a txt file SIDs.txt

> get-content SIDs.txt | % { f-sid $_ }

NOTE: I did not write this, Brian did.

Thanks Brian.

Wednesday, July 26, 2017

Remotely Disable a Windows Firewall (command line)

On a computer in the domain, hit Start, Run, Type:

runas /user:an-administrator@YourDomain cmd "CMD will start with domain admin privliges "

in the CMD window, run:
psxec \\yourremotecomputername cmd

Now run:
netsh firewall set opmode disable "To disable firewall"

Or if you have access to GPO you can do this in the GPO with a GPP

Download PSExec here:

Tuesday, July 04, 2017

2012 r2 support TLS 1.2, but defaults to SSL 3.0 + TLS 1.0.

TL;DR: TLS 1.1 and TLS 1.2 are supported, but disabled by default for most “WinHTTP” client applications, including .NET and hence PowerShell. 

Your Server 2012 r2 should be updated to change the defaults or this issue will reoccur, often.

Background information:
Microsoft .NET supports TLS 1.2, but defaults to SSL 3.0 + TLS 1.0.

Technical Recommendations:
Add the following registry keys to your Windows Server instances. Either save this is a “.reg” file, or alternatively deploy the 4 values using Group Policy Preferences.

Windows Registry Editor Version 5.00



[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]

For servers where PowerShell has TLS 1.2 issues, but enabling it at the registry level causes incompatibility issues, the following snippet can be used:

# EITHER: Enable all current TLS variants:
[System.Net.ServicePointManager]::SecurityProtocol = 'Tls,Tls11,Tls12'

# OR: Enforce TLS 1.2 only and also check Certificate Revocation Lists (CRLs):
[System.Net.ServicePointManager]::SecurityProtocol = 'Tls12'
[System.Net.ServicePointManager]::CheckCertificateRevocationList  = $true  

Monday, May 22, 2017

Find the OS architecture from the command line

Find the OS architecture from the command line. Oh, how many ways are there to do this? 10-15? Maybe more, here is the the easy one, from the command line type "SET PR"

Windows 10 - X64

Windows 2003 - X86

Other ways, just for a laugh (I googled these):


reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
if %OS%==32BIT echo This is a 32bit operating system
if %OS%==64BIT echo This is a 64bit operating system



echo 64-bit...

echo 32-bit...



*** Start ***
@echo off

Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" < CheckOS.txt > StringCheck.txt

If %ERRORLEVEL% == 0 (
    Echo "This is 32 Bit Operating system"
) ELSE (
    Echo "This is 64 Bit Operating System"
*** End ***


wmic os get osarchitecture


(set | find "ProgramFiles(x86)" > NUL) && (echo "%ProgramFiles(x86)%" | find "x86") > NUL && set bits=64 || set bits=32




check for the presence of 
%SYSTEMROOT%\Program Files(x86)


systeminfo | findstr /I type: 


Start-> Run -> winmsd.exe
Under "System Summary"/ System Type you can find the OS version
X64 -> 64 Bit
X86 -> 32 Bit


set p | findstr /i AMD64 > nul
if not errorlevel 1 goto no64
goto eof
code to execute

Blog Archive