Monday, September 25, 2023

Bulk add members in to MS Teams

 MS teams natively does not allow to bulk add members to new or existing teams. The process to add members one by one is pretty troublesome if you need to add 100+ members in one go. Powershell comes to you help in such a scenario.

First install the Microsoft Teams module in Powershell:

Install-Module -Name MicrosoftTeams

In case, its already installed but is of an older version, try to update it using:

Install-Module -Force -Name MicrosoftTeams

Once done, create a simple csv file with 2 columns : Email, Role and fill it up.

Next we need the group Id of the Team to which you want to add the members to. Yes there is powershell command for it as well but it was pretty slow specially when you member of 100's of Teams !!

Simple way was to pull it from the browser window. Just open Teams on the browser window and select the target Team, and look for the param groupId in the url:



Once done, just execute the below script:

#Get users from the CSV

$TeamUsers = Import-Csv -Path "<file_path>"

$TeamID = "<Team_Id / groupId>"

 

#Iterate through each user from the CSV and add to Teams

$TeamUsers | ForEach-Object {

       Add-TeamUser -GroupId $TeamID -User $_.Email -Role $_.Role

       Write-host "Added User:"$_.Email -f Green

}

You should see members getting added one by one:




Sunday, July 23, 2023

Save space on Google Photos by compressing images

For the last few months, I was getting the Google warning that my 15GB of free space was running out and I needed to buy more storage. Upon analysing my space consumption on Google One I realized bulk on my space was being used by Photos. Last I remember it was all free so I had put my android phone photos to be automatically backed up on Google cloud for free.

Then I saw that the policy was updated on June 1, 2021 which not only counts storage for the original high quality images but also the compressed storage saver images. The good thing was that any photo uploaded before June 1, 2021 was not to be counted against the storage.

So first thing I stopped the automated backup and was looking for a day of free time to work out a technical solution. Like I believe most of us, I don't print any poster size photographs. Last I took a print may be decade back. Most of it was for digital consumption i.e. on phone, tab, laptop and at best TV. The resolution required was at best 4K for TV but certainly not the 12 MP per photo which my phone camera was capturing. The solution was to somehow use JPG compression to reduce the photo size but that was not available on the cloud.

So the process I used was:

  1. Downloading photos to PC is cumbersome so I relied on the Google Photos android app. To do select say a day's or month's worth of photos -> select share -> select Copy To. This will force the photos to be download (in original quality on selecting that option) on to your phone's local storage. Let it download and then save in to a preferred folder.
  2. Next connect PC to phone using FTP and download the folder on to the PC.
  3. Next use Irfanview's batch processing to save it as JPG with 90% quality (even 80% is fine). Remember to retain the EXIF, IPTC, etc data




















  4. Once batch is completed, move the output images to the original folder so that the original photos get overwritten. If you wish to back the originals locally - this is the time.
  5. Now the issue is that the date created and date modified is updated to current date and time. If you upload this, this will mess up the Google photos layout. So we need to update the created and last modified timestamps.
  6. Powershell helps us to achieve it:

    $modifyfiles = Get-ChildItem -force *.jpg| Where-Object {! $_.PSIsContainer}
    foreach($object in $modifyfiles)
    {
       $object.CreationTime=[datetime]::ParseExact($object.BaseName.Substring(4),"yyyyMMdd_HHmmss",$null)
      $object.LastWritetime=[datetime]::ParseExact($object.BaseName.Substring(4),"yyyyMMdd_HHmmss",$null)
    }


  7. Once done, FTP it back to the phone and use Google photos.
  8. In Photos, now you will see the images in the cloud tagged with a cloud symbol whereas the local one wont have the symbol.
  9. Delete the ones on the cloud and let it complete.
  10. They backup the rest to the cloud.

And its all done. Save a few GB's doing it :)

Restoring Images Exif Data after upload to Google Photos

 Recently my Google free storage of 15GB is getting full so wished to get the photos back to my local system. Yes we can quickly download it but found that Google has wiped off of the Exif data, specially the dates.


So to restore it, luckily it still retained the file names like : IMG_20230508_110348.jpg

So quickly created the below script and it worked :)


SETLOCAL ENABLEDELAYEDEXPANSION

for %%c in (*.jpg) do ( 

set a=%%~nc

set x=!a:~4,15!

set y=!x:~0,4!:!x:~4,2!:!x:~6,2! !x:~9,2!:!x:~11,2!:!x:~13,2!

echo !y!

"<exiv2_location>\exiv2" -k -M"set Exif.Image.DateTime Ascii !y!" %%c

)


Also it need a PowerShell script to update the created Date and Modified date:


$modifyfiles = Get-ChildItem -force *.jpg| Where-Object {! $_.PSIsContainer}

foreach($object in $modifyfiles)

{

$object.CreationTime=[datetime]::ParseExact($object.BaseName.Substring(4),"yyyyMMdd_HHmmss",$null)

$object.LastWritetime=[datetime]::ParseExact($object.BaseName.Substring(4),"yyyyMMdd_HHmmss",$null)

}