Tuesday 4 August 2015

PowerShell Commands – Get-ChildItem - 1

 

[Note: This article is with respect to Powershell 5.0.10240.16384]

Let us look into the powershell command ‘Get-ChildItem’. This command is used to list the items under a parent item.

Get-ChildItem

The basic form of this command is ‘Get-ChildItem’ without any options. Then it will list the “directories” and “files” in the current directory.

For example if run from the location “C:\Program Files”, it will list the directories and files in “C:\Program Files”

Get-ChildItem –Path <path as string>

This form of the command accepts a “path of the parent” whose child items it will display. For example see the below screen which depicts the working of this command. Here the value of “Path” attribute is “C:\Windows\Log”.

1

    You can put the value of “Path” attribute in single quotes as shown below. This is used if the path  value is having space in it.

2

Also you can avoid specifying “-Path” completely. See the example below

3

If there is no sub-items in the parent directory there will be no result. Please see the example below. Here the directory doesn’t have any content

4

Get-ChildItem –Path <path as string> –Directory

This form of the command will only retrieve the directories in the given path.

Get-ChildItem –Path <path as string> –File

This form of the command will only retrieve the files in the given path. You can’t use the switch attributes “-Directory” and “-Files” simultaneously

{They are called switch attributes because they act like switches. Specifying them will alter the switch the behaviour. They don’t take any values}

Get-ChildItem -Path <path as string> –Recurse

This form of the command will retrieve the files and subdirectories in the directory recursively. That is powershell will travel through all the subdirectories recursively and print the output.

5

Get-ChildItem -Path <path as string> –Recurse –Depth <integer greater than or equal to zero>

This form of the command will retrieve the files and subdirectories in the directory recursively up to the value specified in depth. The items which resides up to the depth will be printed.

If the  value  of  “–Depth” is zero it is same as the command ‘Get-ChildItem -Path <path as string> ‘.

See the below image. The directory “test6” is not visible in the output, since we set the depth to 2.

6

Get-ChildItem -Path <path as string> –Name

This form of the command will retrieve the files and subdirectories in the directory, but list only there name in the output.

7

 

Get-ChildItem -Path <path as string> –Exclude <Pattern as string>

This form of the command will retrieve only files and subdirectories that doesn’t match the pattern specified as the value of “–Exclude” option. Compare the below image with the above one. In the below image I have excluded items using the pattern “test2*”.

8

 

Get-ChildItem -Path <path as string> –Include<Pattern as string>

This form of the command will retrieve only files and subdirectories that match the pattern specified as the value of “–Include” option. Compare the below image with the one for “Get-ChildItem -Path <path as string> –Name”. In the below image I have included only items that match the pattern “test2*”.

9

 

Get-ChildItem –Path <path as string> –Hidden

This form of the command will only retrieve the hidden items in the given path.

There is also one more method to get the hidden files. Use the command form “Get-ChildItem –Path <path as string> –Force

Get-ChildItem –Path <path as string> –ReadOnly

This form of the command will only retrieve the read-only items in the given path.

Get-ChildItem –Path <path as string> –System

This form of the command will only retrieve the system items in the given path.

Monday 3 August 2015

Enabling Guest Account in Windows 10


By default the "Guest" account is disabled in Windows 10. To enable the same please follow the below steps

First of all click/touch on the "Start Menu" icon or press the Windows key in the keyboard. Start typing "Computer Management". Now click on the "Computer Management" item in the search result. See the image below





 This will open a window as shown below.

 

Expand the item named "" by clicking on the arrow on the left side of the item. Now select the sub item "Users". The middle pane will list all the users as shown below. As you can see the "Guest" account will have a black downward arrow. This shows the account is disabled.
 
 

 Double clicking the "Guest" item will bring a window similar to the one shown below. Untick the check box labeled "Account is disabled". Click "Apply" and then click "OK".
 
 

 Now as you can see the "Guest" account is enabled. Be sure to use a complex password for all user accounts.