1

I am creating a script that looks through our WebApp and gets all Site Collections, Sub-Sites and list all the documents with certain pieces of information regarding each item. I have to retrieve items within the folders of each Library which lead me to use a recursive method. However when I use the method I am unsure of how to return the ID of the item (Not GUID). So far anything I have tried has returned a null value. The method I am using is shown below:

Function GetFiles($folder)
{ 
  Write-Host "+"$folder.Name
  foreach($file in $folder.Files)
  {
  Write-Host "`t" $file.Name
  }

  # Use recursion to loop through all subfolders.
  foreach ($subFolder in $folder.SubFolders)
  {
  Write-Host "`t" -NoNewline
  GetFiles($Subfolder)
  }
}

If anyone would know how to return the ID of the file that would great. Thanks in advance.

1 Answer 1

2

If you want to get the ID of the item for the corresponding file, you may simply try:

$file.Item.ID
1
  • Just tried what you suggested and it works perfect. Thanks for your help! Aug 19, 2015 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.