?
Solved

Batch script to scan and echo the result if .pst exist

Posted on 2016-11-17
4
Medium Priority
?
61 Views
Last Modified: 2016-11-26
Looking to do a script that will

1) Use Dsquery to get list of users from the AD OU >  "OU=Blah Users,DC=blah,DC=com"
2) Then for each user above check to see if a .PST exist.
Example path: \\%username%W10\c$\Users\%username%\AppData\Local\Google\Google Apps Sync\
3) If exist Echo Username to a file.

Note: some users in OU may not have a PC so script should not get halted for those.

Thanks in advance.
0
Comment
Question by:GGHC
  • 2
4 Comments
 
LVL 38

Assisted Solution

by:Mahesh
Mahesh earned 1000 total points
ID: 41892786
Try below

Import-Module ActiveDirectory -Erroraction Stop

$Allusers = Get-Aduser -Filter * -SearchBase "OU=usersOU,DC=domain,DC=com" -SearchScope Subtree -ErrorAction SilentlyContinue

[String]$Folderpath = "\\server\share\users\$([Environment]::UserName)\somefolder"

foreach ($user in $Allusers) {

if(Test-Path $Folderpath -Include *.pst)

{ 
    Write-Host "$($user.SamAccountName), Path found successfully" 
                                                                    }

else 
    { Write-Host "$($user.SamAccountName), Path did not found" 
                                                                }

}

Open in new window


replace $Folderpath with your once, do not alter variable code

Mahesh.
1
 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 1000 total points
ID: 41895480
This will generate a csv file with the results:
@echo off
setlocal enabledelayedexpansion
set StartNode=OU=Blah Users,DC=blah,DC=com
set FilePath=AppData\Local\Google\Google Apps Sync\*.pst
set OutFile=C:\Temp\pst.csv

set TmpFile=%Tmp%\~pst.tmp
>"%OutFile%" echo "UserName","ComputerName","PST","Error"
for /f %%a in ('dsquery.exe user "%StartNode%" -o SamId') do (
	set User=%%~a
	set Computer=%%~aW10
	set Error=
	set PST=False
	echo Processing !User! ...
	ping.exe -n 2 !Computer! | find.exe /i "TTL" >NUL
	if errorlevel 1 (
		set Error=Offline
		echo ... offline.
	) else (
		dir /b "\\!Computer!\C$\Users\!User!\%FilePath%" >NUL 2>"%TmpFile%"
		if errorlevel 1 (
			for /f "delims=" %%e in ('type "%TmpFile%"') do set Error=%%e
			echo ... Error: !Error!.
		) else (
			set PST=True
			echo ... file found.
		)
	)
	>>"%OutFile%" echo "!User!","!Computer!","!PST!","!Error!"
)
echo Results saved to '%OutFile%':
type "%OutFile%"

Open in new window

1
 

Accepted Solution

by:
GGHC earned 0 total points
ID: 41896615
Ended up using the following.

@echo off
setlocal enabledelayedexpansion

for /f %%a in ('dsquery computer -o rdn "OU=myuserss,DC=company,DC=com" -limit 0') do (
If Exist \\%%aw10\c$\users\%%a\AppData\Local\Google\Google Apps Sync\*.pst Echo >>%%a c:\Temp\Outlook.txt
)
0
 

Author Closing Comment

by:GGHC
ID: 41902217
clean and basic
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
The article covers five tools all IT professionals should know about, as they up productivity by a great deal!
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question