Solved

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

Posted on 2016-11-17
4
51 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 37

Assisted Solution

by:Mahesh
Mahesh earned 250 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 250 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

688 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