Powershell to get data about multiple profiles

Hi All,

I need help with my powershell script given below. The problem I am having is that it is giving me data only from the profile I am logged into and it does not give data from hidden folders like Appdata in the profile. I need to get data from all the profiles on the system along with hidden folders like appdata. My interest is in step 1 and 4. Thanks in advance.

[pre]

User local storage data check

This script performs the following tasks:

1) Calculates the size of data stored in the users local profile

(NB: does not include hidden files or folders or Outlook .pst files in AppData)

2) Checks for Outlook PST files

3) Checks root of the C drive for any unexpected folders that the users may have created

4) List all the files with their full path that are in the local profile

(NB: can be uncommented if required for further investigation)

The results are sent to an output file called “UserProfileSize.txt” which is created in their Documents folder

1) Calculate size of local profile data

#Reference link below
#https://www.gngrninja.com/script-ninja/2016/5/24/powershell-calculating-folder-sizes
“Total Size of local profile data is {0:N2} MB” -f ((Get-ChildItem C:\users\ -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB) | out-file C:\UserProfileSize.txt

Add-Content C:\UserProfileSize.txt “End of Step 1”

2) Checks for Outlook PST files and lists their full location

#Reference link below
#https://social.technet.microsoft.com/Forums/windowsserver/en-US/8f297c11-2e1c-4302-b3d0-c67f51b687db/howto-create-a-powershell-script-to-search-the-c-drive-for-any-pst-files-and-copy-them-to-a-single?forum=winserverpowershell
Get-WmiObject -Class CIM_DataFile -Filter “Drive=‘C:’ And Extension=‘pst’” | out-file C:\UserProfileSize.txt -Append

Add-Content C:\UserProfileSize.txt “End of Step 2”

3) List any unexpected folders in C

Get-ChildItem c:\ | where Name -NotMatch “Windows|Temp|Users|Program Files|Program Files (x86)|Intel|PerfLogs” | out-file C:\UserProfileSize.txt -Append

Add-Content C:\UserProfileSize.txt “End of Step 3”

4) List all files stored in users local profile

#Reference link below
#https://devblogs.microsoft.com/scripting/use-windows-powershell-to-search-for-files/
Get-Childitem –Path C:\Users\ -Include .pdf,.jpg,.doc,.xls,.ppt -File -Recurse -ErrorAction SilentlyContinue | out-file C:\UserProfileSize.txt -Append

Add-Content C:\UserProfileSize.txt “End of Step 4”

Tells user where to find the results

#"Reference link below
#https://mcpmag.com/articles/2016/06/09/display-gui-message-boxes-in-powershell.aspx
[System.Windows.MessageBox]::Show(‘Completed Successfully. Please find the results in C:\UserProfileSize.txt’)

[/pre]

It looks like you’re using Get-ChildItem to list the directories and files. That cmdlet won’t list hidden files/dirs by default, but you can use the -Force parameter to make those appear.

# Example of Get-ChildItem without force
gci ~

# With force
gci ~ -Force

Hope this helps!

Thanks I figured it out and it gives me what I need. Below is my final script.

[pre]

User local storage data check

This script performs the following tasks:

1) Calculates the size of data stored in the users local profile

(NB: does include hidden files or folders or Outlook .pst files in AppData)

2) Checks for Outlook PST files

3) Checks root of the C drive for any unexpected folders that the users may have created

4) List all the files with their full path that are in the local profile

(NB: can be uncommented if required for further investigation)

The results are sent to an output file called “UserProfileSize.txt” which is created in their Documents folder

$ResultFile = “C:\UserProfileSize.txt”

1) Calculate size of local profile data

#Reference link below
#http://woshub.com/powershell-get-folder-sizes/
gci -force ‘C:\Users’-ErrorAction SilentlyContinue | ? { $_ -is [io.directoryinfo] } | % {
$len = 0
gci -recurse -force $.fullname -ErrorAction SilentlyContinue | % { $len += $.length }
$_.fullname, ‘{0:N2} GB’ -f ($len / 1Gb)
} | out-file $ResultFile

Add-Content C:\UserProfileSize.txt “End of Step 1”

2) Checks for Outlook PST files and lists their full location

#Reference link below
#https://social.technet.microsoft.com/Forums/windowsserver/en-US/8f297c11-2e1c-4302-b3d0-c67f51b687db/howto-create-a-powershell-script-to-search-the-c-drive-for-any-pst-files-and-copy-them-to-a-single?forum=winserverpowershell
Get-WmiObject -Class CIM_DataFile -Filter “Drive=‘C:’ And Extension=‘pst’” | select-object Name | out-file $ResultFile -Append

Add-Content C:\UserProfileSize.txt “End of Step 2”

3) List any unexpected folders in C

Get-ChildItem c:\ | where Name -NotMatch “Windows|Temp|Users|Program Files|Program Files (x86)|Intel|PerfLogs” | out-file $ResultFile -Append

Add-Content C:\UserProfileSize.txt “End of Step 3”

4) List all files stored in users local profile

#This one takes a long time and it searches entire C drive
Get-WmiObject -Class CIM_DataFile -Filter “Drive=‘C:’ And Extension=‘pst’
or Extension=‘docx’
or Extension=‘doc’
or Extension=‘docm’
or Extension=‘xlsx’
or Extension=‘xls’
or Extension=‘xlsm’
or Extension=‘ppt’
or Extension=‘pptx’
or Extension=‘pdf’” | select-object Name | out-file $ResultFile -Append

Add-Content C:\UserProfileSize.txt “End of Step 4”

Tells user where to find the results

#Reference link below
#https://mcpmag.com/articles/2016/06/09/display-gui-message-boxes-in-powershell.aspx
[System.Windows.MessageBox]::Show(‘Completed Successfully. Please find the results in C:\UserProfileSize.txt’)

[/pre]