?
Solved

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

Posted on 2016-11-17
4
Medium Priority
?
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

650 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