5 Simple Commands I Wish I Knew Before I Started Working In A Tech Role

Before starting a tech role in a financial institution, i did not understand the importance of Batch file and Power shell in an organization that largely operates on Windows OS. As such, i hope that this article will help techies who are entering the workforce like me.

Without further ado, here are some quick commands for Batch file and Power shell in Windows that i wish i knew it existed before i started working.

  • Batch file (BAT)

1. Search for user in Active Directory (Power shell)

$User = Get-ADUser -Identity $NTName

$NTName here refers to the logon name for the user.

To extract out different properties e.g. SAMAccountName, Home Directory of the particular user, you can use the following commands.

Get-ADUser -Identity $User -Properties sAMAccountName,HomeDirectory |` 
Select sAMAccountName,HomeDirectory |
Export-CSV -Append “H:\Userproperties.csv"

2. Get users in Active Directory group (Power shell)

$User=Get-ADGroupMember “AD Group Name” | Select sAMAccountName

Typically users are granted permissions based on their groups, so the ability to extract the names of users in selected groups will be important.

3. Echo in different colors for batch file

You can echo in different colors. This will be very useful when you write long batch scripts to run on machines and show users on the progress of the script. It can also be used to highlight a particular section whereby the recipient will have to select if they would like to proceed with certain sections of the script.

Examples from this Stack overflow question

REM Define the ESC environment variablefor /F %a in ('echo prompt $E ^| cmd') do @set "ESC=%a"REM Change based on the numbering of the colors shownecho ^<ESC^>[4m %ESC%[4mUnderline Underline%ESC%[0m
echo ^<ESC^>[32m %ESC%[32mGreen Green Green%ESC%[0m
echo ^<ESC^>[33m %ESC%[33mYellow Yellow Yellow%ESC%[0m

4. Managing Access Control List (ACL) permissions (Power shell)

Want to remove write permissions to users through script? Instead of manually changing the ACL for the folder, you can copy the following script to automate it for you!

Folder ACL permissions
#Set folder path to deny write for user based on their usernameforeach ($row in $Data){

$NTID = $row.NTID
$Path = $row.Path
$acl = Get-Acl $Path
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($NTID,”Write”,’ContainerInherit, ObjectInherit’,”None”,”Deny”) $acl.AddAccessRule($AccessRule) $acl | Set-Acl $Path }

5. Close application using Batch file

REM Close application e.g. OneDrive
Taskkill /IM “OneDrive*” /F

Other than closing the application, you can also perform installations and removal of applications via script as well.

Disclaimer: My opinions are mine only. It will definitely not be the same for everyone. It will depend on the kind of organization and the role that you are working on.

I write about new tech that i’ve been exploring recently. I believe in working hard, being kind and trust that amazing things will happen.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store