Found 989 Articles for Software & Coding

How to install the PowerShell Active Directory module?

Chirag Nagrekar
Updated on 09-Nov-2020 09:40:04

795 Views

To install the active directory module using PowerShell, you need Remote Server Administrator Tools (RSAT) on the server. It should be available in the Roles and Features section of the windows server operating system as shown below and you can enable it from the GUI as well.If you can’t find the RSAT then you can download it from the below location, appropriate to your OS version.https://www.microsoft.com/en-us/download/details.aspx?id=45520Once you have the RSAT tool available in your system, you can use the PowerShell command to enable this feature. To get the Active Directory tools features available in the system, use the below command.ExampleGet-WindowsFeature ... Read More

PowerShell: Wait for the First command to finish

Chirag Nagrekar
Updated on 09-Nov-2020 09:37:19

1K+ Views

We know that PowerShell executes commands sequentially until we specify some parallel Jobs but sometimes the next command executes before the First command because the first command might be taking a long time to retrieve the data. In that case, if you want the previous command to finish first and then the next command to get executed, you can use PowerShell Job functionality.For example, we need to write a script to ask for the user input to terminate process ID but the program should retrieve the process IDs first.Example$job = Start-Job {Get-Process} Wait-Job $job | Out-Null Receive-Job $job $id = ... Read More

How to work the timezone using PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:36:22

850 Views

To get the timezone of the System, you can use the Get-TimeZone command.ExamplePS C:\> Get-TimeZone Id                         : Mountain Standard Time DisplayName                : (UTC-07:00) Mountain Time (US & Canada) StandardName               : Mountain Standard Time DaylightName               : Mountain Daylight Time BaseUtcOffset              : -07:00:00 SupportsDaylightSavingTime : TrueTo Set the TimeZone of the System, you can you the ID or the Name of the ... Read More

How to use function Alias in PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:34:20

396 Views

Like the Parameter alias, we can also set the function alias name to refer to the function as a different name.Examplefunction Test-NewConnection{    [CmdletBinding()]    [Alias("TC")]    param(       [Parameter(Mandatory=$true)]       [String]$Server    )    Write-Output "Testing $server connection" }Now, instead of the Test-NewConnection function name, you can directly use the function alias “TC” as shown below.PS C:\> Tc -Server "Test1-win2k16" Testing Test1-win2k16 connection

How to use an alias() for the parameter in PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:33:23

3K+ Views

PowerShell alias is a good way to use the shortcut name for the Parameter instead of writing the full name of the parameter. For example, you can refer to Server as ServerName, AppID as the ApplicationID.So you don’t have to use the whole name of the parameter and it is easy to remember as well.Examplefunction Aliastest{    param(       [parameter(Mandatory=$true)]       [Alias("Server")]       [string]$ServerName    )    Write-Output "Server name is $ServerName" }Now we can use the Server instead of ServerName while passing the arguments.PS C:\> Aliastest -server "Test1-Win2k16" Server name is Test1-Win2k16

How to find a network adapter driver version using PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 09:31:58

5K+ Views

To find the network adapter driver version using PowerShell, we can use the Get-NetAdapter cmdlet. First, let look at how the network adapter driver version looks like from GUI.Get-NetAdapter will retrieve all the Physical and Virtual network adapters unless specified.This cmdlet has a property called DriverVersion, DriverDate, and DriverProvider. You can select it.ExampleGet-NetAdapter | Select Name, InterfaceDescription, DriverVersion, DriverDate, DriverProviderOutputName                    : Wi-Fi InterfaceDescription    : Intel(R) Wi-Fi 6 AX201 160MHz DriverVersion           : 21.80.2.1 DriverDate              : 2020-02-25 DriverProvider       ... Read More

Difference between single quote (‘) and double quote (“) in PowerShell?

Chirag Nagrekar
Updated on 09-Nov-2020 06:49:46

5K+ Views

There is no such difference between the single quote (‘) and double quote(“) in PowerShell. It is similar to a programming language like Python. We generally use both quotes to print the statements.ExamplePS C:\> Write-Output 'This will be printed using Single quote' This will be printed using Single quote PS C:\> Write-Output "This will be printed using double quote" This will be printed using double quoteBut when we evaluate any expression or print variable it makes a clear difference.$date = Get-Date Write-Output 'Today date is : $date' Today date is : $date Write-Output "Today date is : $date" Today date ... Read More

How to use Push-Location and Pop-Location command in PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 11:12:22

2K+ Views

Push-Location command in PowerShell is used to push (add) the current location to the location stack (Last In First Out (LIFO) - queue) while the Pop-Location is to retrieve the last location from the stack.When the PowerShell console opens there are no locations set to the stack.PS C:\> Get-Location -Stack PS C:\>When you type the Push-Location command it performs two operations at a time. First, it saves the current location to the top of the stack, and second, it browse the path specified. If there is no path specified then it only moves the current location to the stack. For ... Read More

How to get the path of the currently executing script in PowerShell?

Chirag Nagrekar
Updated on 01-Nov-2023 14:43:24

36K+ Views

To get the full path of the script we need to use the $myInvocation command. This is an automatic variable and it is only invoked when the script or the function is executed.$MyInvocation.MyCommand.Path command is useful to get the full path of the script where it resides while $MyInvocation.MyCommand.Name is useful to get the name of the script. Example$mypath = $MyInvocation.MyCommand.Path Write-Output "Path of the script : $mypath"OutputPS C:\WINDOWS\system32> C:\Temp\TestPS.ps1 Path of the script : C:\Temp\TestPS.ps1Please note that we are running the above script from the System32 directory and the output path is C:\temp. To get the script directory, we can ... Read More

How to use the Set-Location command in PowerShell?

Chirag Nagrekar
Updated on 02-Nov-2020 11:07:34

2K+ Views

Set-Location command in PowerShell is used to set the location of the drive from the current directory. The drive could be the local drive, folder path, shared path, registry, or any environmental variable.This command is very useful while writing the script because many times we need multiple files from the same folder and each time we need to mention the full path. This command allows us to set the path at the beginning of the script and then we can directly browse the path from the current directly.Example 1 − The below command sets the location from the C: to ... Read More

Advertisements