Articles on Trending Technologies

Technical articles with clear explanations and examples

What is splatting in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 18-Jan-2021 431 Views

PowerShell splatting is a method to pass the collection of the parameters as a single command unit which makes the command shorter and easier for the user to read commands. Splatting uses the symbol (@) instead of ($) which tells the user that splatting is used and PowerShell is passing a set of values instead of a single value.Splatting in PowerShell was included from the v3.0 onwards and you can pass all parameters in the command.For example, $params = @{    Path = 'C:\Temp\25Aug2020.txt'    Destination = 'C:\test1'    Verbose = $true    Force = $true } Copy-Item @paramsThe splatting ...

Read More

Diameter of a Binary Tree in O(n) [A new method] in C++?

AmitDiwan
AmitDiwan
Updated on 16-Jan-2021 456 Views

The diameter of a binary tree is the (left_height + right_height + 1) for each node. So in this method we will calculate (left_height + right_height + 1) for each node and update the result . The time complexity here stays O(n).Let us first define the struct that would represent a tree node that contains the data and its left and right node child. If this is the first node to be created then it’s a root node otherwise a child node.struct Node {    int data;    struct Node *leftChild, *rightChild; };Next we create our newNode(int data) function that ...

Read More

Diagonal Traversal of Binary Tree in C++?

AmitDiwan
AmitDiwan
Updated on 16-Jan-2021 327 Views

To consider the nodes that are passing between lines of slope -1. The diagonal traversal of the binary tree will be to traverse and print all those nodes present between these lines.Let us first define the struct that would represent a tree node that contains the data and its left and right node child. If this is the first node to be created then it’s a root node otherwise a child node.struct Node {    int data;    struct Node *leftChild, *rightChild; };Next we create our createNode(int data) function that takes an int value and assign it to the data ...

Read More

Construct Pushdown automata for L = {0(n+m)1m2n | m, n = 0} in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 07-Jan-2021 662 Views

We are given with a language “L” and the task is to construct a pushdown automata for the given language which explains that the occurrences of 0’s will be the addition of occurrences of 1’s and 2’s and also, occurrence of 1 and 2 will be minimum one which can also makes the string NULL and it should be accepted by the automata.What is pushdown Automata?A pushdown automata or pushdown automaton or PDA is a technique to implement a context−free grammar in a similar way we design Deterministic Finite Automaton or DFA for a regular grammar. A DFA can operate ...

Read More

Set user-defined variable with table name in MySQL prepare statement?

AmitDiwan
AmitDiwan
Updated on 05-Jan-2021 3K+ Views

Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20) ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(StudentName) values('David'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(StudentName) values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will ...

Read More

How to use PSCustomObject in PowerShell foreach parallel loop?

Chirag Nagrekar
Chirag Nagrekar
Updated on 04-Jan-2021 3K+ Views

To use the PSCustomObject inside the Foreach Parallel loop, we first need to consider how we are using the variables inside the loop.$Out = "PowerShell" ForEach-Object -Parallel{    Write-Output "Hello.... $($using:Out)" }So let see if we can store or change a value in the $out variable.Example$Out = @() ForEach-Object -Parallel{    $using:out = "Azure"    Write-Output "Hello....$($using:out) " }OutputLine |    4 | $using:out = "Azure"      | ~~~~~~~~~~      | The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept      | assignments, such as a ...

Read More

How to work with Invoke-Command Scriptblock output?

Chirag Nagrekar
Chirag Nagrekar
Updated on 04-Jan-2021 9K+ Views

When we simply write the Invoke-Command, it shows the output on the console.ExampleInvoke-Command -ComputerName Test1-Win2k12 -ScriptBlock {Get-Service}OutputIt shows the output along with the computer name.Now let's say you want to sort the output or you want to work with the output you need to store it. It is similar like we store the output in the variable but we can’t store the output inside the scriptblock and display it outside.$ser = @() Invoke-Command -ComputerName Test1-Win2k12 -ScriptBlock {$ser = Get-Service} Write-Output "Services output" $serYou won’t get any output of the above command because Invoke-Command is known to work on the remote computer. ...

Read More

How to check which Azure account is logged in using PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 04-Jan-2021 4K+ Views

To check the logged-in Azure user account in the console using PowerShell, you can check the context of the Azure and for that Get-AZContext command is used.ExampleGet-AzContextOutputIf you are already logged in with multiple user accounts then there may be chances that there are multiple contexts available, to list all the available context, use the below command,ExampleGet-AzContext -ListAvailableOutputYou can choose the context using the Select-AZContext command.

Read More

How to use a variable inside a Foreach-Object Parallel?

Chirag Nagrekar
Chirag Nagrekar
Updated on 04-Jan-2021 4K+ Views

There are two different types of the variable we can use inside foreach parallel loop. One that is declared inside and the other that is declared outside of the foreach parallel loop.Please note − We are discussing here Foreach-Object Parallel loop, featured in PowerShell version 7. For a normal foreach loop inside and outside variables are the same.Variable declared inside the Foreach parallel loop can be used directly with its name. For example, Example$vms = "TestVm1", "TestVM2", "TestVm3" $Vms | ForEach-Object -Parallel{    $var1 = $_    Write-Output "Testing VM: $var1" }OutputTesting VM: TestVm1 Testing VM: TestVM2 Testing VM: TestVm3In ...

Read More

How to use Wait-Process in Powershell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 04-Jan-2021 2K+ Views

Wait-Process cmdlet in PowerShell is used to wait for the process to stop before the execution moves on to the next step.ExampleWe have a snipping tool application running and we need to wait for the process to stop first and then move on to the next step.PS C:\> Get-Process SnippingTool | Select Name, Id, CPU Name          Id    CPU ----          --    --- SnippingTool  7440   2.0625To wait for the process to stop first we will use the Wait-Process command. You can provide ProcessName or ID.Write-Output "Waiting for the Process to Stop" ...

Read More
Showing 50681–50690 of 61,297 articles
Advertisements