Wednesday, March 22, 2023

Learning Linux - Create and Configure File Systems(Part-5)

 In Part 4 of the Learning Linux blog series, we learned how to configure local storage on Linux systems. 

In part 5, We will learn and try to construct daily usage commands to create and configure Linux file systems.

- Create and configure file systems

    mkfs.xfs -L "BackupVolume" /dev/sdb (format disk with xfs file syetem with label)

    mkfs.xfs -i size 500 -L "BackupVolume" /dev/sdb (format disk with xfs file syetem with label and 500 Bypes inode size)

    mkfs.ext4 -L "BackupVolume" -N 500000 /dev/sdb2 (Format disk with ext4 fs with Label and 500K inode numbers)

    xfs_admin (Manage and Monitor xfs filesystem), tune2fs(Manage ext4 filesystem)


- Create, mount, unmount, and use vfat file systems

    vfat (virtual file allocation table)

        sudo fdisk /dev/vdb     t for type; b for w95 FAT32

        sudo mkfs.vfat /dev/vdb1 (Up to 2GB in size)

        sudo mkfs.vfat -F 32 /dev/vdb1  (2 GB and larger)


- Configure systems to mount file systems at or during boot

    sudo mkdir /mybackupvol (create the folder where you want to mount your new volume)

    sudo vi /etc/fstab -----> /dev/vdb1   /mybackupvol       xfs    defaults 0 0 (1st- Device path, 2- mount point, 3- filesystem, 4-(defaults mount option, It can be customize), 5- 0 =fs dump disabled, 6- 1 = root fs, 2 = other fs apart from root), 

    man fstab(for more help)

    sudo systemctl reboot

    sudo blkid  /dev/sda1 (To check the disk sda1's UUID value)


- Configure disk compression(RHEL8 and earlier python based)

    Enabling vdo(virtual data optimizer)

        sudo yum install vdo -y, sudo systemctl start vdo.service

    Using vdo with storage devices

        sudo vdo --create --name=vdo_storage --device=/dev/vdb --vdoLogicalSize=10G (Create vdo storage from physical disk)

        sudo vdostats --human-readable (Check the vdo devices status)

        sudo mkfs.xfs -K /dev/mapper/vdo_storage (Format the vdo device using xfs file system)

    Mounting vdo devices

        Fstab file example: /dev/mapper/vdo_storage /mnt/myvdo xfs _netdev,x-systemd,device-timout=0,x-systemd.requires=vdo.service 0 0 

    RHEL9: lvmvdo: vdo tool has been merged into lvm

        1. Create physical volume: sudo pvcreate /dev/vdb 

2. Create volume group: sudo vgcreate vdo_volume /dev/vdb 

3. Creating lv using vdo enabled: sudo lvcreate --type vdo -n vdo_storage -L 100%FREE -V 10G vdo_volume/vdo_pool1 

4. Create xfs filesystem: sudo mkfs.xfs -L /dev/vdo_volume/vdo_storage

    Create ext4 filesystem: sudo mkfs.ext4 -E nodiscard /dev/vdo_volume/vdo_storage

- Manage layered storage

    Stratis: It's a local storage management tool for Linux 

        Enabling Stratis: sudo yum install stratisd stratis-cli

Creating Stratis Storage Pool: sudo stratis pool create my-pool /dev/vdc  /dev/vdd, sudo stratis pool list (list pools), sudo stratis blockdev(list block devices)

Creating a stratis filesystem: sudo stratis fs create my-pool myfs1, sudo stratis fs(list fs), 

Mounting Stratis filesystem: FSTAB Example: /dev/stratis/my-pool/myfs1 /mnt/mystratis xfs x-systemd-requires=stratisd.service 0 0 

Adding storage device to the Stratis  pool: sudo stratis pool add-date my-pool /dev/vde 

File system snapshot with stratis: sudo stratis fs snapshot my-pool myfs1 myfs1-snapshot 

Mount snapshot:  sudo stratis fs rename developers devfs devfs-bad,  sudo stratis fs rename developers devfs-snapshot devfs, sudo umount /mnt/devstorage, sudo mount /mnt/devstorage

    Taking backup of filesystem:

        sudo stratis fs snapshot my-pool myfs1 myfs1-snapshot (Creating snapshot of stratis fs)

sudo stratis fs rename my-pool myfs1 myfs1-old (Rename current fs)

sudo stratis fs rename my-pool myfs1-snapshot myfs1 (Next, Rename the snapshot fs to previous fs name)

        sudo umount and mount again


-> echo "Thank you :)"

Sunday, February 5, 2023

Learning Linux - Configure Local Storage(Part-4)

In Part 3 of the Learning Linux blog series, We have learned how to operate running Linux systems. 

In part 4, We will explore and try to construct daily usage commands to manage the local storage in the Linux systems.

- List, create, delete, and modify physical storage partitions

    Lsblk - Display the list of block devices, 

    cfdisk - display or manipulate disk partition table, 

    fdisk - manipulate disk partition table

- Configure and manage swap space 

    Create and manage swap space

  1. swapon --list ( Show the list of swap partition), 
  2. mkswap /dev/sdb3 - format the disk as swap partition, 
  3. swapoff/swapon /dev/sdb3 - enable/disable devices and files for paging and swapping

    Use a file for swap

  1. sudo dd if=/dev/zero of=/swap bs=1M count=1024 (Create a zerod file for 1 GB), 
  2. sudo chmod 600 /swap ( Change the swap file permission to allow only to root user), 
  3. mkswap /swap, swapon /swap

- Manage and configure LVM storage

    lvmdiskscan(check the LVM disk/volumes), 

    Adding Physical Volumes:

  • pvcreate /dev/sdb /dev/sdc(create the Physical Volumes), pvs(show the list of PVs),  

    Adding Volume Group and Extending

  1. sudo vgcreate my_volume /dev/sdb /dev/sdc (create VG), 
  2. sudo vgextend my_volume /dev/sdd (Extending the Volume Group by adding another Physical volume), 
  3. sudo vgs (shows the volume group), 

    Reduce VG:

  • sudo vgreduce my_volume /dev/sdd (Remove PV from existing VG), sudo pvremove /dev/sdd (Remove PV)

    Create Logical Volume:

  • sudo lvcreate --size 2G --name partition1 my_volume( my_volume = VG), sudo lvs (show the list of LVs),

    Extending or Resizing the LV:

  1. sudo lvresize --extents 100%VG my_volume/partition1(Extend partion1 by 100%), 
  2. sudo lvresize --size 2G my_volume/partition1(resize the partion1 to 2GB), 
  3. sudo lvresize --resizefs --size 3G my_volume/partition1(!!! Resize the lv using resizefs parameter if  lv is holding the file system)

    Format the lv by using filesystem(xfs):

  • sudo mkfs.xfs /dev/my_volume/partition1(format lv by xfs)

  - Create and configure encrypted storage

    Encrypted Storage:

        PlainMode:

  1. sudo cryptsetup --verify-passphrase open --type plain /dev/sdd mysecuredisk
  2. sudo mkfs.xfs /dev/mapper/mysecuredisk (Format the encrypted disk with xfs filesystem)

        LuksEncryption:

  1. sudo cryptsetup luksFormat /dev/sdd (format disk with luks)
  2. sudo cryptsetup luksChangeKey /dev/sdd (Change Encryption key)
  3. sudo cryptsetup open /dev/sdd mysecuredisk(Open the encrypted disk)

- Create and manage RAID devices

    Create and manage RAID Devices

  1. sudo mdadm --create /dev/md0 --level=1 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd (Create RAID 1 using 3 disks)
  2. sudo mdadm --manage /dev/md0 --add /dev/vde (Add disk to existing raid 1 array)
  3. sudo mkfs.xfs /dev/md0 (Format raid disk-md0 to xfs)

  • sudo mdadm --stop /dev/md0 (You may stop raid disk - md0)
  • sudo mdadm --zero-superblock /dev/sdb /dev/sdc /dev/sdd(Zeroed (remove) the disks)

  • sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc --spare-devices=1 /dev/sdd(Create RAID 1 with Spare disk)
  • cat /proc/mdstat (Check the RAID Status)
  • sudo mdadm --manage /dev/md0 --add /dev/sdd (Add additional disk to existing RAID Disk - md0)
  • sudo mdadm --manage /dev/md0 --remove /dev/sdd(remove disk from RAID Array)

- Create, manage, and diagnose advanced file system permissions

  • getfacl, setfacl 
    • Example: sudo setfacl --modify user:aaron:rw examplefile (Assigning special permission to user aaron)
  • getfacl examplefile, 
  • sudo setfacl --remove user:john specialfile(Remove ACL Permission)
  • sudo setfacl --recursive --modify user:john:rwx collection/ (Set adv permission on directory)
  • sudo setfacl --modify mask:r examplefile (Assigning mask permission to read-only, Mask limit the permission),
  • Chattr (Making file attributes)
    • Example:
      • chattr +a newfile (Making file append for new content only)
      • chattr +i newfile (Making file Immutable)
      • lsattr newfile (Checking if file has immutable attr enabled)

- Setup user and group disk quotas for filesystems

    User and group filesystem Quotas

  1. dnf install quota ( install the quota app), 
  2. Enable Quota on xfs filesystem:
  3. sudo vim /etc/fstab, 
      • /dev/vdb1 /mybackups xfs defaults, usrquota, grpquota,  0 2 
  4. sudo systemctl reboot

    Enable quota for ext4 file system:

  1. sudo quotacheck --create-files --user --group /dev/vdb2
  2. sudo quotaon /mnt/

        Check user quota:
  • sudo edquota --user aaron (Checking quota for user edit mode, replace user with group if required)
  • sudo quota --user aaron (Checking quota for user)
  • sudo quota --edit-period (Change the grace period)


-> echo "Thank you :)"

Wednesday, January 18, 2023

Learning Linux - Operate Running Systems(Part-3)

In part 2 of this learning Linux basics, we tried constructing basic shell scripts using the condition, Loops, etc.

In the part 3 series of Learning Linux, We will try to perform the below Linux operations,

    1. boot, reboot, shutdown

    2. Change Linux OS operating modes

    3. Gain root access after interrupting the boot process

    4. troubleshoot bootloaders


- Boot, reboot, and shutdown a system safely:

    Reboot & shutdown: systemctl restart / systemctl poweroff

    schedule shutdown/reboot: shutdown 2:00 'shutting down for maintenance at 2 AM morning'

    shutdown -r 2:00 'rebooting  for maintenance at 2 AM morning'

- Boot or change the system into different operating modes

    Operating Modes(Targets)

- Graphical.target

- Multi-user.target

- Emergency.target

- Rescue.target

     Change Mode: systemctl set-default multi-user.target, 

     Switch Mode: systemctl isolate graphical. target

- Interrupt the boot process in order to gain access to a system

    Red Hat 8: 

    - Open GRUB Edit mode while booting

       


    - In the edit mode, Insert text rd.break at the end of the Linux GRUB syntax. CTL + X to proceed with the boot

   

    - You will be in Emergency target mode with swich_root login. The root file system will be default mounted as ro(read only). To check type: mount | grep /sysroot

    - You must remount the root file system with rw(read write) mode to change the root password. Run the below command to remount in rw mode: mount -o remount rw /sysroot.

    - Type cd /sysroot to change directory to root from Swich_root. 

    - Now you should be able to change root password. Type passwrd root 

    -  then at the end we must create a special file touch /.autorelabel . reboot


    Red Hat 9:

    - Start GRUB loader in edit mode and change crash kernel mode from ro to rw. At the end of Kernel syntax, we will add string: init=/bin/bash


    - Now, press CTRL + X to continue with boot process

    - In the next couple of seconds, you should be already in with root access. Type passwrd root to change the root password and type: touch /.autorelabel and exec /sbin/init to continue the boot process to load the OS.

- Install, configure and troubleshoot bootloaders
           When you in a situation where GRUB is unable to load the OS or getting errors. You might have to rebuild the GRUB config to fix the boot issue. Please follow the below steps

  1. Boot from bootable USB drive and start into 'Troubleshooting' mode
  2. you're in rescue mode and you should be prompted to try couple of options like 1. Continue: This will try to search for root filesystem and mount it for you, 2. Read-Only mode: Mount root fs in ro, 3. Skip to shell, 4. Quit(reboot).
  3. Select 1, Press 'Enter' and type: chroot /mnt/sysroot to get into root access mode
  4. Now, To Generate new GRUB config type: grub2-mkconfig -o /boot/grub2/grub.cfg (BIOS), grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg(EFI)
  5. Now, GRUB should be install on the first sector of OS disk. you need to find the physical disk holding the /boot and install the grub conf there.

lsblk (to find the block devices)

                grub2-install /dev/sda ( This will place the GRUB in first sector of disk /dev/sda) OR 

dnf reinstall grub2-efi grub2-efi-modules shim(EFI) 

  


    6. exit from troubleshoot mode to reboot the system

- Modify the GRUB configuration file 

    Open /etc/default/grub file in vim with sudo access. Modify the required parameters and save the file 

  •     grub2-mkconfig -o /boot/grub2/grub.cfg (BIOS), grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg(EFI)
  • reboot

- Diagnose and manage processes

Process Management: 

  • Examples: ps, ps aux (ax=all processes, u=user oriented format), 
  • ps u -U rahul ( All processes running by user rahul), 
  • ps lax (show nice values for processes), 
  • ps faux (show the parent of process), 
  • top,  pgrep -a syslog (process grep),  
  • nice -n <value -20/19> process id/name
  • renice <value> process id(sudo renice 7 8290), 
  • lsof -p 1(show the open files used by process id), Example: sudo lsof | grep sshd |  grep -i reg | sed 's/.* //g'(reg files used by ssd),
  • sudo lsof /var/log/messages(what process using the file)

        Process Signals: 

  • kill -l (list the valid signals) , 
  • pkill -KILL bash ( Kill the matching processes), 
  • ctrl + z (Pause the open program/process) and fg will bring it back(fg - foreground), 
  • sleep 180 & (Make the program run in background) and fg <id> will bring it back., 
  • bg 1 (make the first background program to run), 

- Locate and analyze system log files

        rsyslog = rocket-fast system for log processing(Default daemon for linux OS)

           Following log file: example tail -f /var/log/messages

        Journalctl

  • Example: journalctl /bin/sudo(Logs for a program), 
  • journalctl -u sshd.service(Log reported by a unit - service), 
  • journalctl -f(follow mode), 
  • journal -p err ( filter the logs by priorities like info, warning, err, crit), 
  • sudo journalctl -p info -g '^c' (g = grep, search for logs starting letter c),
  • last (who logged in), lastlog  

-> echo "Thank you :)"





Saturday, December 24, 2022

RDPClient_SSL(TsSslEventHandshakeContinueFailed): 2022-12 Cumulative Update for Windows Server 2016 for x64-based Systems (KB5021235)

 Hi there, 

Post installation of this update - "2022-12 Cumulative Update for Windows Server 2016 for x64-based Systems (KB5021235)" on one of the domain controllers in Azure VM.  We started facing a weird RDP Authentication issue where users with even the correct credential failed to take an RDP session of remote systems in another network(site).

After investigating further, We noticed the below warning message in the event log for RDP Service-

RDPClient_SSL: An error was encountered when transitioning from TsSslStateHandshakeInProgress to TsSslStateDisconnecting in response to TsSslEventHandshakeContinueFailed (error code 0x80004005).

In the end, we had to uninstall this CU Update - KB5021235 from the domain controller which has fixed the issue.

So if you're having a similar issue, I request you to please try uninstalling this update or hold for installation. 

Hopefully, the Microsoft update team will fix this issue very soon.

Thank you,

 

Wednesday, December 14, 2022

Learning Linux - Create a simple shell script(Part-2)

 In part 1 of this blog series, We have seen how to work on essential Linux commands. In part 2, We will assist you to understand the basic logic and loop format while creating your first bash script. 

Prerequisites: I am hoping you have basic knowledge and experience with Linux. 

- Use scripting to automate system maintenance tasks

Scripting: #! Shebang - #!/bin/bash , # comment a line or text

- Conditional Logic(if)

IF Example: 

if [condition block] 

then

Command section

elif [condition block] 

then 

Command section

else 

Command section

fi 

    Conditional Operators

              
                

        






   

    -Processing shell command exit codes

        Exit Code: run 'echo $?' post running any command to know the exit code


    - Use Looping constructs (for, etc.) to process file, command line input

For Loop: Perform repetitive tasks 

Example: 

for mission in $(cat mission-names.txt)

do 

create-and-launch-rocket $mission

done

    while Loop usage: wait in the loop until specific condition matches/create infinite loops/Menu driven programs

Example:

while [$rocket_status = "launching"]

do

sleep 2

rocket_status = rocket-status $mission_Name

done

-> echo "Thank You :) "

Tuesday, November 29, 2022

Learning Linux - Essential Commands(Part-1)

As part of this blog series, I am trying to consolidate the most common Linux commands and their usage in a very simplified manner so that you may recall them while you're performing any related tasks.


- Log into the local/remote system
SSH, Telnet, VNC Server/client

- Read, and use System Documentation
command --Help, Manual Pages with man command, 
Searching for commands - apropos, Tab/auto-completion

- Create, Delete, Copy, and Move Files and Directories
Listing files & Directories - ls, absolute path/relative path,
Current/Working Directory - cd, Creating file - touch,
copying file - cp [source] [destination], Move Files - mv [source] [destination]
Deleting files & Directory - rm,

- Create and manage hard links
Introduction to iNode - stat [file], hard link - ln [path_to_target_file] [Path_to_link_file],
Limitations - Only Hard links to files, not folder, Only Hard links to files on same filesystem,

- Create and manage soft links
soft links - ln -s [path_to_target_file] [Path_to_link_file], readlinks [soft link file]

- List, set, and change standard file permissions
Owner & Groups - chown [user] [file], chgrp [group] [file], Files & Directory Permission - 
chmod [permissions] [file/directory], 

- SUID, SGID, and Sticky Bit
SUID - chmod 4664 file, SGID - chmod 2664 file, Stickybit - chmod 1777 file

- Search for files
find [path/to/direcotory] [search parameters], 
                Search Parameters - Name - find -name felix, 
                Search Parameters - Modified time - find -mmin [minute],  
                Search Parameters - file size - find -size [size], 
                Search expressions - find -name "f*" -mmin [minute] # AND Operator, 
                find -name "f*" -o -mmin [minute] # OR Operator,   
                find -not -name "f*" ,  find /! -name "f*" # NOT Operator, 
                # Find files with permissions- find -perm 664 // find -perm u=rw,g=rw,o=r, 
                # Find files with at least permission- find -perm -664 // find -perm -u=rw,g=rw,o=r, 
                # Find files with any of these permissions- find -perm /664 // find -perm /u=rw,g=rw,o=r

- Compare and manipulate file content
cat, tac, tail, head, Transforming text: sed 's/canda/canada/g' file.txt(lookupmode), 
                Sed -i 's/canda/canada/g' file.txt(inplacemode)
cut -d '' -f 1 file.txt(delmitedmode), Uniq & Sort: uniq file.txt, sort file,
Comparing files: diff diff file1 file2, diff -c diff file1 file2 , diff -y diff file1 file2

- Search files using Grep
Searching with grep: grep [option] 'search pattern' file, 
                grep 'centos' /etc/os-release, 
                grep -i 'centos' /etc/os-release(Non-case-insensetive),
grep -r 'centos' /etc/os-release(recursive), 
                grep -ir 'centos' /etc/os-release(Case-Ins.+recursive),                 
                grep -vi 'centos' /etc/os-release(invert-match), 
                grep -wi 'centos' /etc/os-release(words), 
                grep -oi 'centos' /etc/os-release(only-matching), 

- Analyze text using basic regular expressions
Regex Operators: ^, $, ., *, +, {}, ?, |, [], (), [^], 
                The Line Begin with: ^, 
                The line End with: $, 
                Match AnyONE Characters: . Example: grep -r 'c.t' /etc/,
Escape for special characters: \: Example: grep '\.' \etc\login.defs, 
                Match the previous element o or more matches: *, 

- Extended Regular Expressions
Previous elements can exist "this many" times: {}, Example: egrep -r '10{,3}' /etc/, 
                Make the previous element optional: ?, Example: egrep -r 'disabled?' /etc/, 
                Match one thing or the other: |, Example: egrep -ir 'enabled?|disabled?' /etc/, 
                Range or Sets: [], Example: egrep -r 'c[au]t' /etc/, 

-  Use input-output redirection (>, >>, |, 2>, etc.)
Stdin(<), stdout(1>, >), and stderr(2>), Redirection: >, >> , 
                Example: over right, date > output.txt, 
                append, date >> output.txt 
                heredoc(<<EOF) and here string(<<<) 
                Example: sort <<EOF .Input value. > EOF (Here Document or heredoc), 
                bc <<< 1+3+6 == 10(here string)

- Archive, backup, compress, unpack, and uncompress files
1. Archiving, 2. Compression, 3. Backup
tar = tape archive, 
                Listing: tar --list --file archive.tar, 
                Creating tar file: tar --create --file archive.tar file1, 
                Add to exising archive: tar --append --file archive.tar file1,
Extracting: tar --extract --file archive.tar --directory /tmp/

- Compress and Uncompress files
Common archiving tools: tar, zip 
Common Compress and Uncompress tools: gzip, bzip2, xz
Compress: gzip file1, bzip2 file2 xz file3, 
                Decompression: 
                 gunzip file.gz or gzip --Decompress file.gz, 
                 bunzip file.bz2 or bzip2 --Decompress file.bz2,
unxz file.xz or xz --Decompress file.xz

Common Compress and Uncompress with tar: 
                 tar --create --file archive.tar file1, 
                 tar --create --gzip --file archive.tar.gz file1(with combining gzip),
tar --create --bzip2 --file archive.tar.bz2 file1(with combining bzip2), 
                tar --create --xz --file archive.tar.xz file1(with combining xz)
Autocompress: 
                 tar --create --autocompress --file archive.tar.gz file1(Select compression utility automatically), 
                 tar --extract --file    archive.tar.gz 

- Backup files to a Remote System
Syncing two Directories: 
                rsync, Example: rsync -a pictures/ aroon@9.9.83.2:/home/aroon/pictures/
Disk Imaging: dd, 
                 Example: sudo dd if=/dev/vda of=diskimage.raw bs=1M status=progress

- Securely transfer files between systems
Securely transfer files: 
                 scp, Example: scp aaron@192.168.1.27:/home/aaron/myfule.tgz /home/aaron/myfiles.tgz (Copy from remote to local), 
                 scp /home/aaron/my_archive.tar aaron@192.168.1.27:/home/aaron/my_archive.tar (local to remote), 
                 scp aaron@192.168.2.37:/home/aaron/my_archive.tar aaron@192.168.1.27:/home/aaron/my_archive.tar ( remote to remote)

Securely transfer files: sftp, Example: sftp aaron@192.168.1.27(connecting sftp server), 
                 get family.jpg (interactive command(get) to download to local), 
                 get -r /picture (interactive command(get) to download recursive to local), 
                 put family.jpg (interactive command to upload to local),  
                 put -r /my_pictures (interactive command to upload recursive  to local)




-> echo "Thank You :) "


Monday, April 19, 2021

Exchange Server - Creating addition Global Address List(GAL)

Hi There, 

I hope you are doing well!

I would like to guide you through the process of creating an additional Global address list in the Exchange-Onprem environment. This solution has been tested on Ex2019.

Requirement: Create an additional address book for users who belongs to a different business unit with a different domain name/ different SMTP domain name (Example - mydomain.com). 


Step1:  Create New GAL using the recipient filter to a windows email address like *@mydomain.com

New-GlobalAddressList -Name "AAA Global Address List" -RecipientFilter {((Alias -ne $null) -and (((ObjectClass -eq 'user') -or (ObjectClass -eq 'contact') -or (ObjectClass -eq 'msExchSystemMailbox') -or (ObjectClass -eq 'msExchDynamicDistributionList') -or (ObjectClass -eq 'group') -or (ObjectClass -eq 'publicFolder'))) -and (WindowsEmailAddress -like "*@mydomain.com") )}

Update-GlobalAddressList "AAA Global Address List"


Step2: Create the following Address list like All Users, All Room, All DLs, etc.

- All Distribution Lists

New-AddressList -Name "AAA All Distribution Lists" -RecipientFilter {((Alias -ne $null) -and (ObjectCategory -like 'group') -and (WindowsEmailAddress -like "*@mydomain.com"))}

- All Rooms

New-AddressList -Name "AAA All Rooms" -RecipientFilter {((Alias -ne $null) -and (((RecipientDisplayType -eq 'ConferenceRoomMailbox') -or (RecipientDisplayType -eq 'SyncedConferenceRoomMailbox'))) -and (WindowsEmailAddress -like "*@mydomain.com"))}

- All Users

New-AddressList -Name "AAA All Users" -RecipientFilter {((Alias -ne $null) -and (((((((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (-not(Database -ne $null)) -and (-not(ServerLegacyDN -ne $null)))) -or (((ObjectCategory -like 'person') -and (ObjectClass -eq 'user') -and (((Database -ne $null) -or (ServerLegacyDN -ne $null))))))) -and (-not(RecipientTypeDetailsValue -eq 'GroupMailbox')))) -and (WindowsEmailAddress -like "*@mydomain.com"))}


Step3: Create an Offline Address Book 

New-OfflineAddressBook -Name "AAA Offline Address Book" -AddressLists "AAA Global Address List"
Update-OfflineAddressBook "AAA Offline Address Book" 


Step4: Create an Address Book Policy which we will later apply to the respective business users.

New-AddressBookPolicy -Name "AAA ABP" -AddressLists "AAA All Distribution Lists", "AAA All Users" -RoomList "AAA All Rooms" -OfflineAddressBook "AAA Offline Address Book" -GlobalAddressList "AAA Global Address List"


Step5:  Finally, Apply this policy to a few test accounts to confirm if it's working as expected using the below command. Later, you can apply to all users.

Set-Mailbox -identity Username -AddressBookPolicy "AAA ABP"

Note: After creating this new GAL, If the Email Address Policy is set to default to all users, everyone within the organization will be able to see this new GAL in ADDRESS BOOK. To prevent it, you must apply the new 'Email Address Policy' individually to all users in the different business units (As per the above requirement).

*You may replace the domain - mydomain.com and name format "AAA ---" according to your company naming format.

Feel free to comment if you have any questions or concerns.

Best Regards,
Rahul