Articles on Trending Technologies

Technical articles with clear explanations and examples

How to use Array Splatting in PowerShell?

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

Splatting is the method to pass the collection of parameters as a single unit so it will be easier for the command to read. Array splatting uses the splat values which do not require parameter names. The values must be in positional number order in the array.We have a below copy example, in which we are copying one file from the source to the destination. Now we are not specifying the parameters here because we will use the positional parameter for the source path and the destination path.If we check the help for those parameters, we will come to know ...

Read More

How to use Hashtable splatting in PowerShell?

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

Splatting is the way to pass the collection of the parameters to the command as a single value. It uses the Hashtable splatting means that we can pass the Name and Value pair combination. We can use the named positional parameter for this with the values we want to provide.For example, First, we will check how we run the Copy-Item command here without splatting, $params = @{    Path = 'C:\Temp\25Aug2020.txt'    Destination = 'C:\test1'    Verbose = $true    Force = $true } Copy-Item @paramsAnother Example, $hash = @{    From = 'harris@Microsoftmail.com'    To = 'Jacob@MicrosoftMail.com'    SMTP ...

Read More

What is splatting in PowerShell?

Chirag Nagrekar
Chirag Nagrekar
Updated on 18-Jan-2021 487 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 492 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 372 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 907 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
Showing 50681–50690 of 61,299 articles
Advertisements