Resolve DNS Address Using PowerShell

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

18K+ Views

To resolve the DNS address using PowerShell, we need to use the Resolve-DNS address command. This command works similarly to Nslookup command.To resolve the A record (Name -> IP), you can directly provide the hostname and by default, it will retrieve all the records for the particular address.ExampleResolve-DnsName -Name Test1-win2k12OutputName                            Type  TTL Section IPAddress ----                            ----  --- ------- --------- Test1-Win2k12.labdomain.local    A   1200 Answer 192.168.0.107-Name parameter doesn’t accept the multiple-input. Only the single ... Read More

Install PowerShell Active Directory Module

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

1K+ 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

Wait for the First Command to Finish in PowerShell

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

2K+ 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

Work with Timezone Using PowerShell

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

981 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

Use Function Alias in PowerShell

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

537 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

Use an Alias for the Parameter in PowerShell

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

4K+ 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

Find Network Adapter Driver Version Using PowerShell

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

8K+ 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

ES6 Default Parameters in Nested Objects JavaScript

AmitDiwan
Updated on 09-Nov-2020 09:06:58

595 Views

Yes, you can pass default parameters in nested objects.Following is the code −ExampleFollowing is the code −function callBackFunctionDemo({ cl: { callFunctionName = "callBackFunction", values = 100 } = {} } = {}) {    console.log(callFunctionName);    console.log(values); } //This will print the default value. // 100 callBackFunctionDemo(); //This will print the given value. //500 callBackFunctionDemo({ cl: { values: 500 } });To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo296.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo296.js callBackFunction 100 callBackFunction 500

Decrease Size of a String Using Preceding Numbers in JavaScript

AmitDiwan
Updated on 09-Nov-2020 09:05:13

119 Views

Let’s say our original string is the following with repeated letters −var values = "DDAAVIDMMMILLERRRRR";We want to remove the repeated letters and precede letters with numbers. For this, use replace() along with regular expression.ExampleFollowing is the code −var values = "DDAAVIDMMMILLERRRRR"; var precedingNumbersInString = values.replace(/(.)\1+/g, obj => obj.length + obj[0]); console.log("The original string value=" + values); console.log("String value after preceding the numbers ="); console.log(precedingNumbersInString);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo295.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo295.js The original string value=DDAAVIDMMMILLERRRRR String value ... Read More

Automate Object in JavaScript to Set Key as Null

AmitDiwan
Updated on 09-Nov-2020 09:03:13

180 Views

For this, use Object.keys() and set one key on each iteration as null using a for loop..ExampleFollowing is the code −var objectValues = {    "name1": "John",    "name2": "David",    "address1": "US",    "address2": "UK" } for (var tempKey of Object.keys(objectValues)) {    var inEachIterationSetOneFieldValueWithNull = {       ...objectValues,        [tempKey]: null    };    console.log(inEachIterationSetOneFieldValueWithNull); }To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo294.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo294.js { name1: null, name2: 'David', address1: 'US', address2: 'UK' ... Read More

Advertisements