Found 2043 Articles for Microsoft Technologies

How to list the directory content in PowerShell?

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

30K+ Views

To display the directory content, Get-ChildItem cmdlet is used. You need to provide the path of the directory or if you are in the same directory, you need to use only Get-ChildItem directly. In the below example, we need to display the contents of the D:\temp directory.When Get-ChildItem command is run outside of this directory then the path of the directory should be provided. This is called the absolute path.PS C:\> Get-ChildItem D:\Temp\CommandWhen this command is run directly within the directory then simply run this command. This is called a relative path.PS D:\Temp> Get-ChildItem OutputDirectory: D:\Temp Mode       ... Read More

How to retrieve specific file(s) information using Get-ChildItem in PowerShell?

Chirag Nagrekar
Updated on 22-Jan-2020 12:40:58

2K+ Views

When the item (file) path is provided to the Get-ChildItem cmdlet, it extracts the file information like Name, LastWriteTime, Size, etc.ExampleGet-ChildItem -Path D:\Temp\style.cssOutputDirectory: D:\Temp Mode                LastWriteTime         Length Name ----                -------------         ------ ---- -a----       08-12-2017     10:16            393 style.cssCommandTo get the full properties of the file then you need to use fl * (Format-List *) pipeline command.Get-ChildItem -Path D:\Temp\style.css | fl * OutputPSPath            : Microsoft.PowerShell.Core\FileSystem::D:\Temp\style.css ... Read More

What are the parameters supported by Get-ChildItem in PowerShell?

Chirag Nagrekar
Updated on 22-Jan-2020 12:39:08

235 Views

Below parameters are supported by Get-ChildItems. Get-ChildItem[[-Path] ] [[-Filter] ] [-Include ] [-Exclude ] [-Recurse] [-Depth ] [-Force] [-Name] [-Attributes ] [-FollowSymlink] [-Directory] [-File] [-Hidden] [-ReadOnly] [-System] []

Which methods are supported by Get-ChildItem in PowerShell?

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

322 Views

There are methods or functions which are useful for directories and file operations.Methods for the directory.TypeName: System.IO.DirectoryInfo Name                      MemberType ----                      ---------- Create                    Method CreateObjRef              Method CreateSubdirectory        Method Delete                    Method EnumerateDirectories      Method EnumerateFiles            Method EnumerateFileSystemInfos  Method Equals                    Method ... Read More

Which properties are supported by the Get-ChildItem in PowerShell?

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

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

What is Get-ChildItem cmdlet in PowerShell?

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

856 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.

How to check if a process is exited from the system after executing Stop-Process command in PowerShell?

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

694 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"}

What is the 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

How to confirm before stopping the process in PowerShell?

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

241 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

How to stop the specific instance of the process in PowerShell?

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

277 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

Advertisements