Properties Supported by Get-ChildItem in PowerShell

Chirag Nagrekar
Updated on 22-Jan-2020 12:37:46

4K+ Views

When you pipeline the parameter Get-Member (alias gm) and filter out properties then there will be two different properties that will be displayed. One is for the File and another is for the Folders.Get-ChildItem propertiesCommandGet-ChildItem | gm | where{$_.Membertype -eq "Property"}Output** Properties of Directory TypeName: System.IO.DirectoryInfo Name              MemberType Definition ----              ---------- ---------- Attributes        Property   System.IO.FileAttributes Attributes {get;set;} CreationTime      Property   datetime CreationTime {get;set;} CreationTimeUtc   Property   datetime CreationTimeUtc {get;set;} Exists            Property   bool Exists {get;} Extension ... Read More

Print All Combinations of Balanced Parentheses in C++

sudhir sharma
Updated on 22-Jan-2020 12:36:07

772 Views

In this problem, we are given an integer n. Our task is to print all possible pairs of n balanced parentheses.Balanced parentheses are parentheses pairs that have a closing symbol for every corresponding opening symbol. Also, pairs should be properly nested.Let’s take an example to understand the problem, Input: n = 2 Output: {}{} {{}}To solve this problem, we need to keep track of pairs of brackets. The initial count of brackets is 0. Then we will recursively a function till the total bracket count is less than n. Count brackets, recursively call for brackets based on the count. If ... Read More

Print All Combinations of Factors in C++

sudhir sharma
Updated on 22-Jan-2020 12:33:42

302 Views

In this problem, we are given a number n. Our task is to print all combinations of factors of n.Let’s take an example to understand the topic better −Input: 24 Output: 2 2 2 3 2 4 3 8 3 4 6 2 12For this, we will use recursion function which will find a combination of factors of the number. And we will store all our combinations in an array of array.ExampleThis code will show the implementation of our solution. Live Demo#include using namespace std; vector factor_Combo; void genreateFactorCombinations(int first, int eachFactor, int n, vectorfactor) {    if (first>n || eachFactor>n) ... Read More

Print All Combinations of Points that Can Compose a Given Number in C++

sudhir sharma
Updated on 22-Jan-2020 12:31:18

236 Views

In this problem, we are given the total score n. Print all combinations of basketball points that are 1, 2, and 3 that give a total score of n.Let’s see an example to understand the problem, Input: 4 Output: 1 1 1 1 1 1 2 1 2 1 1 3 2 1 1 2 2 3 1To solve this problem, we will use recursion. And fix and resources for rest values n-s, where s is the score. If the combination adds up to n, print the combination.ExampleThe code shows the implementation of our code − Live Demo#define MAX_POINT 3 #define ... Read More

Get-ChildItem Cmdlet in PowerShell

Chirag Nagrekar
Updated on 22-Jan-2020 12:30:53

1K+ Views

Get-ChildItem (alias: dir) in Powershell is used to get the items inside the container. This container could be the Folders, Registry or the certificate store. You can retrieve items from one or more specified locations. This command works similar to the dir in command prompt but PowerShell provides a modern way to extract the data.

Check If a Process Has Exited After Stop-Process in PowerShell

Chirag Nagrekar
Updated on 22-Jan-2020 12:30:25

988 Views

After killing the process using Stop-Process command in PowerShell, you can determine if the process is really terminated from the system with HasExited function.For example, we will kill Notepad process and check if Notepad process still exists in the system?$notepad = Get-Process notepad | Stop-Process if($notepad.HasExited){"Process is terminated"} else{"Process is still running"}

Use of Passthru Parameter in Stop-Process in PowerShell

Chirag Nagrekar
Updated on 22-Jan-2020 12:29:42

3K+ Views

With the Passthru parameter, PowerShell returns the output in the console. For example, below notepad.exe process with ID 12344 will be stopped and the same will be displayed in the console with the Passthru parameter. Earlier it was not the case with only Stop-Process.PS C:\WINDOWS\system32> Stop-Process -Id 12344 -PassThru     Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName     -------  ------    -----      -----     ------     --  -- -----------         227      13     2800      13440       0.19  12344   1 ... Read More

Confirm Before Stopping a Process in PowerShell

Chirag Nagrekar
Updated on 22-Jan-2020 12:29:14

322 Views

To get the consent from the user before stopping process or instance, -confirm parameter is used.ExampleIn the below example, we will stop notepad.exe process with –Id 4900 using –Confirm parameter.PS C:\WINDOWS\system32> Stop-Process -Id 4900 -Confirm Confirm Are you sure you want to perform this action? Performing the operation "Stop-Process" on target "notepad (4900)". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):Similarly, you can use the –Confirm parameter for stopping the process with Name.PS C:\WINDOWS\system32> Stop-Process -Name Notepad -Confirm

Stop Specific Instance of a Process in PowerShell

Chirag Nagrekar
Updated on 22-Jan-2020 12:28:44

356 Views

To stop the specific instance of the process, Process ID needs to provide to Stop-Process cmdlet.ExampleIn the below example, we need to stop Notepad process with instance ID 25400.OutputHandles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName -------  ------    -----      -----     ------     --  -- -----------     228      14     3156      13680       0.13   4900   1 notepad     232      14     3196      13752       0.16  25400   1 notepadStop-Process -Id 25400 Now, when Get-Process command is run, there will be no process running with –Id 25400.CommandPS C:\WINDOWS\system32> Get-Process -Name notepadOutputHandles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName -------  ------    -----      -----     ------     --  -- -----------     227      13     2808      13492       0.14   4900   1 notepad

Print All Distinct Characters of a String in Order in C++

sudhir sharma
Updated on 22-Jan-2020 12:28:43

1K+ Views

In this problem, we are given a string. Our task is to print all distinct characters of the string in the order they appear in the string.Let’s take an example to understand our problem, Input: tutorials Point Output: uralsPnThere are multiple ways to solve this problem but we will discuss the most effective one. The simple one includes the nesting of loops.For this, we will use two arrays of size 256(8-bit characters are stored).First we will initialize all values of counter array to 0 and all values of index array to n (length of string). On traversal of the string ... Read More

Advertisements