Translate

Monday, October 21, 2024

Golang - Create Azure User

Function to ccreate a new user account in Azure using msgraph-sdk-go:


// creates a user in Azure with a minimal number of properties set
func CreateBaseAzureUser(strDisplayName, strMailNickName, strUserPrincipleName, strPassword, strEmployeeId string)(error){
	logger.NLog.Info().Msg("CreateBaseAzureUser Started: dn: " + strDisplayName + " mnn: " + strMailNickName + " upn: " + strUserPrincipleName + " eid: " + strEmployeeId)
	//employee id check: check if there is already a current user with the same employee id 
	//get the base azure user properties by employeeId
	user, err := AzureGetBaseUsersByPropertyFilter("employeeId", strEmployeeId)
	if user != nil {
		if len(user.GetValue()) != 0 {
			logger.NLog.Error().Err(err).Msg("CreateBaseAzureUser Error: " + strEmployeeId)
			strM := "An Azure user with the employeeID " + strEmployeeId + " already exits."
			utils.PostMessageT("it-help@internews.org", "Azure Account Creation Error for Emp. ID: " + strEmployeeId, strM)
			return errors.New(strM)
		}
	} 	
	requestBody := graphmodels.NewUser()
	accountEnabled := true
	// Enable the account
	requestBody.SetAccountEnabled(&accountEnabled) 
	// Display Name
	requestBody.SetDisplayName(&strDisplayName) 
	// Mail Nick Name
	requestBody.SetMailNickname(&strMailNickName) 
	// User Principal Name
	requestBody.SetUserPrincipalName(&strUserPrincipleName)
	// Employee ID
	requestBody.SetEmployeeId(&strEmployeeId)
	// Password
	passwordProfile := graphmodels.NewPasswordProfile()
	forceChangePasswordNextSignIn := true
	passwordProfile.SetForceChangePasswordNextSignIn(&forceChangePasswordNextSignIn) 
	passwordProfile.SetPassword(&strPassword) 
	requestBody.SetPasswordProfile(passwordProfile)

	if azureGgraphConnector == nil{
		err := InitializeAzureGraph()
		if err != nil{
			logger.NLog.Error().Err(err).Msg("CreateBaseAzureUser InitializeAzureGraph Error")
			utils.PostMessageT("it-help@internews.org", "CreateBaseAzureUser InitializeAzureGraph Error for Emp. ID: " + strEmployeeId, err.Error())
			return err
		}
	}
	
	users, err := azureGgraphConnector.AppClient.Users().Post(context.Background(), requestBody, nil)

	if err != nil {
        logger.NLog.Error().Err(err).Msg("CreateBaseAzureUser error: " + strEmployeeId + " " + strDisplayName)
		utils.PostMessageT("it-help@internews.org", "Azure Account Creation Error: " + strEmployeeId + " " + strDisplayName, err.Error())
        return err
    } else {
		logger.NLog.Info().Msg("CreateBaseAzureUser user created: " + *users.GetDisplayName())
	}
	return nil
}

Friday, September 13, 2024

TSQL - Update Using A List of Values

I needed to update around 800 addresses from a list of addresses in a spreadsheet. I saved the spreadsheet as csv and then formated the csv fields into a list of values. Then I wrote an SQL select statement that took the list of values and made it into a subquery that I could join on the address table.

This is the finale SQL with just a subset of the values:

update aglA 
set aglA.telephone = lh.phone
from address aglA 
join (select * from (values('100000','1 707 822 4226'),('100010','1 707 826 9681'),('100030','1 707 445 8248'))as x( res_id, phone))lh on lh.res_id = aglA.res_id 

Wednesday, February 28, 2024

Salesforce - Export Developer Console Query Results

After the query is run, rught click on the query results and select Inspect. Look for the table tag, and then click Copy and then Copy element. Paste the copied results into Excel.

Tuesday, December 19, 2023

Logitech C920 - Not Recognized by Windows 11

For me, the issue was caused by the USB ports. The webcam would not work on the USB hub that I was using with my laptop, a ThinkPad, and it would only work on certain ports on the ThinkPad USB-C Dock Gen 2.

Wednesday, July 26, 2023

Windows 10 Polish Key Combinations

Install the Polish language pack. Then use the following key combinations for the Polish characters:

Right-Alt + Z = ż
Right-Alt + X = ź
Right-Alt + S = ś
Right-Alt + C = ć
Right-Alt + L = ł
Right-Alt + O = ó
Right-Alt + E = ę
Right-Alt + A = ą
Right-Alt + N = ń

Wednesday, March 29, 2023

A Simple Collatz Proof

A Simple Collatz Proof Proof by exhaustion and reductio ad absurdum.

1. It has already been proven that the Collatz conjecture is true for a large set of odd numbers. This is the set Po. The largest number in the set is Pn.
2. The Collatz series for all numbers n repeats at the interval 4n + 1. This set, the extended set of the Collatz series for all odd numbers, is the set Pi. For Pn, there are an infinite subset of numbers in Pi that are greater than Pn. This is the set, Pm.
3. Consider the next highest odd number, an odd number that is the largest number in the Po set plus two: N = Pn + 2.
4. Either some number in the Collatz series for N will be equal to a number in the Pm set or a number in the Po set, or they will not. If no number in the Collatz series for N is equal to a number in either set, there would exist an infinite set of odd numbers where the Collatz conjecture is false, with a series of numbers that never intersect with the series of numbers where the conjecture has been proven true. Given the size of the Pm set and the Po set, this is impossible! Therefore, the conjecture is true for all numbers.
5. Q.E.D.

Note: I separated out the Pm set to show that for any odd number that is tested, there will always be an infinite set of odd numbers known to be true for Collatz that are greater than the number being tested. So, even when the numbers in a series are rising, they can still intersect with a number that, indirectly, has been proven true for the conjecture.

Example for step 2: For n = 27, the Collatz series will be the same for 27, 4(27) + 1, 4(4(27) +1) + 1, 4(4(4(27) +1) + 1) + 1, and so on. And this would extend with all of the numbers that make up the Collatz series for 27: 41, 31, 47, 71, 107, 161, 121, 91, 137, 103, 155, 233, 175, 263, 395, 593, 445, 167, 251, 377, 283, 425, 319, 479, 719, 1079, 1619, 2429, 911, 1367, 2051, 3077, 577, 433, 325, 61, 23, 35, 53, 5, and 1.

Friday, December 9, 2022

Windows - Microsoft Edge browser pops up after logging in

I've been dealing with this issue on a new laptop and had an aha moment this morning. The lock screen settings in MS Windows might cause the browser to open after you log in when the lock screen preview background is set to Windows spotlight. This behavior seems to be inconsistant.