PowerShell
20 AugustGet Password Policy for User in Active Directory in PowerShell
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 […]
20 AugustGet Proxy Settings in PowerShell
1. Introduction In environments where internet access is controlled through a proxy, PowerShell scripts often need to be aware of these settings to function correctly. This article will guide you through different methods to get proxy settings using PowerShell, focusing on the proxy address, port, and its operational status. 2. Using Net.WebProxy Class The Net.WebProxy […]
20 AugustGet Memory Usage Percentage in PowerShell
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. […]
20 AugustGet Fully Qualified Domain Name in PowerShell
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 […]
20 AugustLoop Through JSON File in PowerShell
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 = […]
20 AugustGet History of Commands in PowerShell
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 […]
16 AugustGet Password Expiration Date in PowerShell
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. […]
16 AugustGet AD User Home Directory and Home Drive in PowerShell
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 […]
16 AugustGet Mapped Drives for All Users in PowerShell
Using net use Command Use the net use command to get mapped drives for all users in PowerShell. net use New connections will be remembered. Status Local Remote Network ------------------------------------------------------------------------------ OK K: \\DESKTOP-NKK10JM\JavaProject Microsoft Windows Network OK Z: \\DESKTOP-NKK10JM\Share Microsoft Windows Network The command completed successfully. In the above example, we used the net use […]
- 1
- 2
- 3
- …
- 19
- Nextkeyboard_arrow_right