Hi folks. i’m working on pulling some data from Sharepoint on-prem, using Powershell and currently it outputs perfectly when i use “Write-Host”. But i need to add the values to an open array and order it so i can Export to CSV file. Can you tell me why the $Hashtable array is empty and does not store any of the filename and fileURL values? Write-Host shows them, but $hashtable is empty. Thank you
#Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$Hashtable = @()
Function GetFiles($Folder) {
foreach ($file in $Folder.Files) {
if ($file.Name -like "*.htm*") {
Write-Host $file.Name
Write-Host $file.URL
$Hashtable += New-Object PSObject -Property @{
‘filename’ = $file.Name;
‘fileURL’ = $file.URL;
}
}
}
#Loop through all subfolders and call the function recursively
foreach ($SubFolder in $Folder.SubFolders) {
if ($SubFolder.Name -ne "Forms") {
Write-Host "`t" -NoNewline
GetFiles($Subfolder)
}
}
}
#Get the Site collection
$Site = Get-SPSite "https://dev.MyCompany.com/sites/Problems”
#Loop through all Sub Sites
foreach($Web in $Site.AllWebs){
Write-Host "—————————————————–"
Write-Host "Site Name: '$($web.Title)' at $($web.URL)"
Write-Host "—————————————————–"
foreach($list in $Web.Lists){
#Filter Doc Libs, Eliminate Hidden ones
if(($List.BaseType -eq "DocumentLibrary") -and ($List.Hidden -eq $false) ){
GetFiles($List.RootFolder)
}
}
}