• Eric Marsi

Random PowerShell Code Snippets, PS Functions, & Links Library

Updated: Jul 11


The below list a continued collection of random PowerShell Code Snippets & Functions that I use for various things. If there is anything that you wish to have added, let me know in the comments below!

Get Microsoft 365 Tenant ID

Found a different version of this on the internet, but modified it slightly for anyone not wanting to know the exact spot

$TenantName = "Contoso"

(Invoke-WebRequest https://login.windows.net/$($TenantName).onmicrosoft.com/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split(‘/’)[3]

Generate-NVKey - PowerShell Function

This PowerShell Function generates a random 32-bit Hex string that can be used for various tasks such as security. This is based on the output of New-Guid however since the 13th character is always a 4, we have to modify this to give us a completely random yet unique response.


function Generate-NVKey
	{
		function New-12Bit
			{
				((new-guid).guid).replace('-','').SubString(0,12)
			}
		(((New-12Bit) + (New-12Bit) + (New-12Bit)).ToUpper()).SubString(0,32)
	}
Generate-NVKey

If you would like an output that is of any value 0-36 characters in length, change the 32 in the above function to the desired number.

Example Output:


Redeem Microsoft 365 Business Subscription Link

https://portal.office.com/Commerce/ProductKeyRedeem.aspx



54 views0 comments