Check If File Contains String in Bash
Java tutorial for beginners
by Arpit Mandliya
5M ago
1. Overview Searching for strings in text files is a common task in bash, used in scenarios like log file analysis and configuration file searches. This article explores various methods to check if file contains String, including both case-sensitive and case-insensitive approaches. 2. Introduction to Problem Statement Let’s consider a log file named server.log: 2023-11-24 10:00:00 INFO Starting server process 2023-11-24 10:00:05 ERROR Failed to bind to port 8080 2023-11-24 10:00:10 INFO Server listening on port 9090 2023-11-24 10:01:00 WARN Database connection timeout Our goal is to check if ..read more
Visit website
PowerShell Get Password Policy for User in Active Directory
Java tutorial for beginners
by Arpit Mandliya
8M ago
Using Get-ADDefaultDomainPasswordPolicy Cmdlet The Get-ADDefaultDomainPasswordPolicy is used to get the default password policy for the specified domain. We can use it differently in different use cases; let’s learn a few of them below. Use the Get-ADDefaultDomainPasswordPolicy cmdlet with the -Current parameter to get the default password policy for the currently logged-on user in an active directory. Here, the user can be an Administrator or any XYZ name. Get-ADDefualtDomainPasswordPolicy -Current LoggedOnUser ComplexityEnabled : True DistuniguishedName : DC=maslab,DC=c ..read more
Visit website
Powershell Get Proxy Settings
Java tutorial for beginners
by Arpit Mandliya
8M ago
Using netsh Command netsh winhttp show proxy Current WinHTTP proxy settings: Proxy Server(s) : 10.0.0.21:8080 Bypass List : (none) On Windows machines, the above command is useful for checking the current proxy settings and it is beneficial for verifying proxy settings and troubleshooting network connectivity. We used this command to check the current proxy settings on Windows. Here, the netsh (Network Shell) is the command-line tool in Windows, utilized to communicate with different network-related settings. The winhttp specified the context for the netsh, which indicated that ..read more
Visit website
PowerShell Get Memory Usage Percentage
Java tutorial for beginners
by Arpit Mandliya
8M ago
We can have multiple use cases for getting memory usage percentages. For example: Getting overall memory usage percentage Getting overall memory usage percentage history Getting memory usage percentage for one/all processes Let’s learn them one by one. Overcall Memory Usage Percentage We can use Get-Counter and Get-WmiObject cmdlets to retrieve the overall memory usage percentage. Let’s explore them below in detail. Use Get-Counter Cmdlet Use the Get-Counter cmdlet to get total memory usage in percentage. $performance_counter = Get-Counter '\Memory\% Committed Bytes In Use' $usedMemoryPer ..read more
Visit website
PowerShell Get Fully Qualified Domain Name
Java tutorial for beginners
by Arpit Mandliya
8M ago
Using Environment Variable Use an environment variable to get a fully qualified domain name. $computer_name = $env:COMPUTERNAME $fqdn = $env:USERDNSDOMAIN Write-Output "Fully Qualified Domain Name: $computer_name.$fqdn" Fully Qualified Domain Name: MAS-DC-01.MASLAB.COM First, we assigned the value of the environment variable ($evn:COMPUTERNAME) to the $computer_name variable. The environment variable COMPUTERNAME stored the current computer’s name or you can say the current host’s name; both meaning the same. Then, we assigned the $fqdn variable with the value of the $env:USERDNSDOMAIN env ..read more
Visit website
PowerShell Loop Through JSON File
Java tutorial for beginners
by Arpit Mandliya
8M ago
Using ConvertFrom-Json Cmdlet We can use the ConvertFrom-Json cmdlet to traverse the JSON file with first and nested-level keys; Let’s explore them below. Traverse JSON File Containing First-Level Keys Use ConvertFrom-Json with the foreach loop to traverse the JSON file having first-level keys only. { "name": "John Christoper", "age": 40, "city": "Washington" } $jsonData = Get-Content -Path "./file.json" -Raw | ConvertFrom-Json foreach ($current_property in $jsonData.PSObject.Properties) { Write-Host "$($current_property.Name): $($current_property.Value)" } name: John Chri ..read more
Visit website
PowerShell Get History of Commands
Java tutorial for beginners
by Arpit Mandliya
8M ago
Using Get-History Cmdlet Using Get-History to get the complete history of the executed commands in PowerShell. Get-History Id CommandLine -- ----------- 1 Get-History 2 ls 3 ping example.com 4 Get-History 5 Get-History 6 Get-Process 7 Get-Service In this example, the history of the commands is obtained using the Get-History cmdlet. On execution of the above code, we can see the list of executed commands is returned and displayed on the screen with their respective Id (showing the sequence of the execution of the commands) and the CommandLine (showing the text or comm ..read more
Visit website
Bash Check If Output Contains String
Java tutorial for beginners
by Arpit Mandliya
8M ago
Using grep Command Use grep with the -q option to check if output contains String in Bash. #!/bin/bash output=$(ls -l) search_string=".csv" # String to search for in the output if echo "$output" | grep -q "$search_string"; then echo "The output contains the search string." else echo "The output does not contain the search string." fi The output contains the search string. In this example, the ls command is used to get the list of directories and files in the current working directory. Here, the -1 parameter is used with the ls command to get detailed information about the list and ..read more
Visit website
PowerShell Get Password Expiration Date
Java tutorial for beginners
by Mehvish Ashiq
8M ago
Using Get-ADUser Cmdlet Use the Get-ADUser cmdlet to get the password expiration date for one specific user in an Active Directory. Get-ADUser -Identity Administrator –Properties "SamAccountName", "msDS-UserPasswordExpiryTimeComputed" | Select-Object -Property "SamAccountName", @{Name="PasswordExpiryDate";Expression={[DateTime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} SamAccountName PasswordExpiryDate -------------- ------------------ Administrator 8/27/2023 4:35:46 PM The Get-ADUser cmdlet is used to get one or multiple users from an active directory. We ..read more
Visit website
PowerShell Get AD User Home Directory and Home Drive
Java tutorial for beginners
by Mehvish Ashiq
8M ago
Using Get-ADUser Cmdlet We use Get-ADUser differently based on various use cases; let’s explore a few of them below. Get Home Directory & Drive for One User Use the Get-ADUser cmdlet to get the ad user’s home directory and home drive. $username = 'Administrator' Get-ADUser -Identity $username -Properties * | Select HomeDirectory, HomeDrive HomeDirectory HomeDrive ------------- --------- \\mas-dc-01\Users\Administrator\Documents D: First, we initialized the $username variable with the Administrator; this was the use ..read more
Visit website

Follow Java tutorial for beginners on FeedSpot

Continue with Google
Continue with Apple
OR