General Helpful Tech Stuff for Work

Windows CLI Commands

  1. Get Wi-Fi passwords for all networks you were connected to:

for /f "skip=9 tokens=1,2 delims=:" %i in ('netsh wlan show profiles') do @echo %j | findstr -i -v echo | netsh wlan show profiles %j key=clear

2. Group Policy report based on your account.

gpresult /h c:report.html

3. Show your IP and if it’s a duplicate, get rid of your ip, and get a new one.

ipconfig /all

ipconfig /release

ipconfig /renew

4. Find hidden shares

net share

example of result shown below, $ indicates hidden share)

Share name Resource Remark

-------------------------------------------------------------------------------

C$ C:\ Default share

D$ D:\ Default share

IPC$ Remote IPC

ADMIN$ C:\Windows Remote Admin

...

PowerShell Scripts

  1. Change a large number of users passwords in AD.

    With AD don’t forget to use the command Import-module ActiveDirectory

    # Set the new password

    $newPassword = ConvertTo-SecureString -String "SuperPassword123!@#" -AsPlainText -Force

    # Loop through users Student1 through Student24

    for ($i = 1; $i -le 24; $i++) {

    $username = "Student$i"

    # Change password for each user

    Set-ADAccountPassword -Identity $username -NewPassword $newPassword -Reset

    }

    # Optional: Force users to change their password at next logon

    foreach ($username in (1..24 | ForEach-Object { "Student$_" })) {

    Set-ADUser -Identity $username -ChangePasswordAtLogon $true

    }

  2. Create A large number of users in AD from an excel file

    Install-Module -Name ImportExcel -Force -AllowClobber

    # Import the Excel module

    Import-Module ImportExcel

    # Specify the path to the Excel file

    $excelFilePath = "C:\Path\To\Your\File.xlsx"

    # Import data from Excel

    $data = Import-Excel $excelFilePath

    # Loop through each row in the Excel file and create users

    foreach ($row in $data) {

    $username = $row.Username

    $password = ConvertTo-SecureString -String $row.Password -AsPlainText -Force

    $givenName = $row.GivenName

    $surName = $row.SurName

    $displayName = "$givenName $surName"

    $ou = $row.OrganizationalUnit # Specify the Organizational Unit (OU) where you want to create users

    # Create user

    New-ADUser -SamAccountName $username -UserPrincipalName "$username@yourdomain.com" -Name $displayName -GivenName $givenName -Surname $surName -DisplayName $displayName -Enabled $true -Path $ou -AccountPassword $password -ChangePasswordAtLogon $true

    }

    # Optional: Display a message indicating that user creation is complete

    Write-Host "User creation from Excel file completed."

  3. Add all users in one group called “Trainers” to a new group called “Techs”

    # Import the Active Directory module

    Import-Module ActiveDirectory

    # Specify the names of the source and target groups

    $sourceGroupName = "Trainers"

    $targetGroupName = "Techs"

    # Get all users from the source group

    $sourceGroupMembers = Get-ADGroupMember -Identity $sourceGroupName -Recursive | Where-Object { $_.objectClass -eq 'user' }

    # Add each user to the target group

    foreach ($user in $sourceGroupMembers) {

    Add-ADGroupMember -Identity $targetGroupName -Members $user.SamAccountName

    }

    # Display a message indicating that the users have been added to the target group

    Write-Host "Users from '$sourceGroupName' group added to '$targetGroupName' group."

  4. Export to CSV the membership details of all users in a specific OU

    # Import the Active Directory module

    Import-Module ActiveDirectory

    # Specify the path where you want to save the CSV file

    $outputFilePath = "C:\Path\To\Export\GroupMembershipDetails.csv"

    # Specify the distinguished name of the target OU

    $ouDistinguishedName = "OU=YourOU,DC=yourdomain,DC=com"

    # Get all user objects in the specified OU

    $usersInOU = Get-ADUser -Filter * -SearchBase $ouDistinguishedName -Properties MemberOf

    # Create an array to store the results

    $results = @()

    # Loop through each user and retrieve group membership details

    foreach ($user in $usersInOU) {

    $userDetails = [PSCustomObject]@{

    UserName = $user.SamAccountName

    DisplayName = $user.DisplayName

    MemberOf = ($user.MemberOf | Get-ADGroup | Select-Object -ExpandProperty Name) -join ', '

    }

    $results += $userDetails

    }

    # Export the results to a CSV file

    $results | Export-Csv -Path $outputFilePath -NoTypeInformation

    # Display a message indicating that the export is complete

    Write-Host "Group membership details exported to $outputFilePath."

Cisco IOS Commands

  1. Clear the switch config and delete vlan.dat

    sw(config): write erase

    sw(config): delete flash:vlan.dat

    sw#: reload

    2. Copy config to TFTP server

    Switch(config)# tftp-server flash:FILENAME tftp_ip_address

    (Replace FILENAME with the name you want to give to the exported configuration file, and replace tftp_ip_address with the IP address of your TFTP server.)

    Switch# copy running-config tftp:

    Address or name of remote host []? 1.1.1.1 (your tftp server IP)

    3. Upgrade Cisco IOS from USB

    Switch(config)# usbflash0:YOUR_IOS_IMAGE.bin flash:

    Switch(config)# show flash:

    Switch(config)# boot system flash:YOUR_IOS_IMAGE.bin

    Switch(config)# write memory

    Switch# show version

    4. In ROMMON (ROM Monitor) mode on a Cisco switch, you can recover or change the enable password without deleting the entire configuration. Follow these steps:

    1. Reboot into ROMMON mode: You need to restart or power cycle the switch and break into ROMMON mode during the boot sequence. You can do this by pressing Ctrl + Break or Ctrl + C during the switch's boot process.

    2. Initialize the Flash File System:

      switch: flash_init

    3. Load the Helper Files:

      switch: load_helper

    4. Rename Configuration Files: Rename the configuration file to avoid it being loaded during the boot process:

      switch: rename flash:config.text flash:config.old

    5. Boot the Switch:

      switch: boot

      This will boot the switch without loading the configuration.

    6. Enter Privileged Exec Mode:

      Switch> enable

    7. Enter Global Configuration Mode:

      Switch# configure terminal

    8. Change the Enable Password:

      Switch(config)# enable secret NEW_PASSWORD

      Replace NEW_PASSWORD with your desired new enable password.

    9. Rename Configuration Files Back:

      Switch(config)# no rename flash:config.text flash:config.old

    10. Write Changes to Memory:

      Switch(config)# write memory

    11. Reload the Switch:

      Switch(config)# exit Switch# reload

    Confirm the reload when prompted.

    After the switch restarts, it should have the new enable password.


Linux Commands

  1. Mount a CD that has an ISO

    sudo mkdir /mnt/cdrom

    lsblk

    sudo mount /dev/sr0 /mnt/cdrom

    ls /mnt/cdrom

    2. Change a file to an executable and run it

    chmod +x your_script.sh

    ./your_script.sh

    3. Extend the root directory by 10GB (using LVM)

    df -h

    lvextend -L +10G /dev/mapper/vg-root

    resize2fs /dev/mapper/vg-root

    xfs_growfs /

    df -h

    (Without LVM)

    df -h

    sudo fdisk /dev/sda

    Type p to print the existing partition table and note the starting sector of the root partition. Delete the root partition (e.g., /dev/sda1). Recreate the root partition with the same starting sector but a larger size. Save and exit.

    sudo resize2fs /dev/sda1

    df -h

    4. Check what audio devices and what audio managers are on a Linux red hat system

    #This will provide information about available audio devices

    aplay -l

    #To check the audio mixer and see what controls are available

    amixer -D pulse scontrols

    #PulseAudio is commonly used on Linux systems. You can use the pacmd command to check PulseAudio information

    pacmd list-sinks

    #ALSA (Advanced Linux Sound Architecture) is another audio system. You can use the alsamixer command to interactively explore and configure audio settings

    alsamixer

    #Check the configuration files for your audio manager. For example, if you are using PulseAudio, you might find configuration files in the /etc/pulse/ directory.

    ls /etc/pulse/

    #To check if PulseAudio is running, you can use

    systemctl status pulseaudio

    #check the audio levels

    alsamixer -Dhw

5. ALSAMIXER SCRIPT

Save alsamixer settings script:

Create a script, let's say save_alsamixer_settings.sh, to save the current alsamixer settings:

bashCopy code

#!/bin/bash # Save alsamixer settings alsactl store

Make this script executable:

bashCopy code

chmod +x save_alsamixer_settings.sh

  1. Reload saved alsamixer settings at startup:

Create a script, for example, reload_alsamixer_settings.sh, to reload the saved alsamixer settings at startup:

bashCopy code

#!/bin/bash # Restore alsamixer settings alsactl restore

Make this script executable:

bashCopy code

chmod +x reload_alsamixer_settings.sh

  1. Configure the script to run at startup:

To execute the reload_alsamixer_settings.sh script at startup, you can add it to the system startup configuration. One way to do this is by adding it to the /etc/rc.local file.

Edit /etc/rc.local:

bashCopy code

sudo nano /etc/rc.local

Add the following line before exit 0:

bashCopy code

/path/to/reload_alsamixer_settings.sh

Replace /path/to/ with the actual path where reload_alsamixer_settings.sh is located.

Save the file and exit the text editor.

Make sure that /etc/rc.local is executable:

bashCopy code

sudo chmod +x /etc/rc.local

Now, on system startup, the reload_alsamixer_settings.sh script will be executed, restoring the saved alsamixer settings.

Note: Be cautious when modifying system startup scripts, as it can affect system behavior. Always make sure to test changes in a safe environment before applying them to production systems.

Excel Formulas

  1. You can use the CONCATENATE function or the "&" operator in Excel to combine the names from columns A and B and display the result in column C. Here's an example formula that you can use:

=CONCATENATE(A1," ",B1)

OR

=A1 & " " & B1

This formula will combine the name in cell A1 with a space and the name in cell B1, and display the result in cell C1. You can then copy the formula down the entire column to apply it to all rows in the spreadsheet.

Note that if you have blank cells in columns A or B, the formula will display an error. To prevent this, you can use the IF function to check if a cell is blank before concatenating the values. Here's an example:

=IF(OR(ISBLANK(A1),ISBLANK(B1)),"",CONCATENATE(A1," ",B1))

OR

=IF(OR(ISBLANK(A1),ISBLANK(B1)),"",A1 & " " & B1)

This formula will check if either cell A1 or B1 is blank, and if so, display a blank cell in column C. If both cells contain values, it will concatenate them as before.

2. COUNTIF/COUNTIFS:

=COUNTIF(range, criteria) =COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...)

Counts the number of cells that meet a single or multiple criteria.

3. Open a password protected Excel worksheet

Open VBA in excel (ALT + F11)

Click the sheet you need to open

Paste this code into it

Sub PasswordBreaker()

'Breaks worksheet password protection.

Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub

Run the Macro (press F5)

Use the generated code