0

I started doing some powershell scripting today for my work and I can find this page: http://technet.microsoft.com/en-us/library/hh849827.aspx

This shows all the Cmdlets that I am using in the scripts, but I cannot find the documentation on how to use the returned objects of these Cmdlets. For example, I am using the Get-ChildItem cmd to get all the files in a dir recursively. Then I am using a ForEach loop like this:

 $dest = "C:\Users\a-mahint\Documents\Testing\Dest"
                    $destlist = Get-ChildItem $dest -Recurse

                    foreach ($file in $destlist){
                    write-host "File: $file"
                    write-host $file
                    $result = test-path -path "C:\Users\a-mahint\Documents\Testing\Src\*" -include $file.Name
                        if (-not $result){
                          Copy-Item $file -Destination "$backup"
                        }

                    }
                    write-host "Done copying deleted files"

Except I have no idea what type of object a $file is...In the documentation above, it just says it outputs a System.Object, but that doesn't help at all. I want to know all the properties of this object so I can use them to debug.

4
  • 1
    Based on your code above, $dest is under c:\, which is a PSDrive which uses the file system provider. When you use Get-ChildItem with that type of provider, you get a sequence of System.IO.FileSystemInfo objects, either DirectoryInfo or FileInfo depending on whether each item is a directory or file. Commented Jun 13, 2013 at 17:53
  • $file.GetType() will reveal it is actually a FileInfo or DirectoryInfo, based on System.IO.FileSystemInfo. Commented Jun 13, 2013 at 18:33
  • @EBGreen post that as your solution. That's what I used Commented Jun 13, 2013 at 19:11
  • I would except that it doesn't answer the question that you actually asked. It answers a specific subset applying to the specific issue that you were trying to resolve. In a general sense though, Get-Help, Get-Command, and Get-Member should be your three most frequently used cmdlets while you are learning Powershell. Commented Jun 13, 2013 at 20:43

3 Answers 3

2

From a question I asked one time Andy Arismendi supplied some links for me to read.

You can download said specification: 2.0 and 3.0.

$file = Get-Item C:\foo.txt

Remember there is a $file | Get-Member command you can use to view the objects methods and properties. Also since everything in PowerShell is an Object you can always do $file.GetType() and then Bing that type.

Sign up to request clarification or add additional context in comments.

Comments

1

Get-ChildItem "C:\Windows\System32\WindowsPowerShell\v1.0\en-US" -Filter *.txt

Comments

0

Here is a decent reference for get-childitem.

http://technet.microsoft.com/en-us/library/ee176841.aspx

What kind of file details are you needing exactly?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.