简体   繁体   English

需要扫描所有域计算机上的.pst文件

[英]Need to scan all domain computers for .pst files

I am new to powershell sctipting, like Brand new. 我是全新的powershell sctipting。 I have some experience using Exchange powershell but thats always been for very specific items like adjust calendar permissions and such. 我有一些使用Exchange PowerShell的经验,但这一直是针对非常具体的项目,如调整日历权限等。 Nothing to robust. 没有什么可以强大的。
Currently I am working on a powershell script to push out via Group policy that will run aa search on each domain PC. 目前我正在开发一个powershell脚本,通过组策略推出,该策略将在每台域PC上运行搜索。 I've been getting help from a co-worker but he isn't available right now and I have a hard time following him sometimes. 我一直在寻求同事的帮助,但他现在无法使用,我有时很难跟着他。 I am this site and its user might be able to assist me. 我是这个网站,它的用户可能能够帮助我。 What I am trying to do(and I believe I am close to) is pulling a list of drives for each computer on the domain. 我想要做的事情(我相信我很接近)正在为域中的每台计算机提取驱动器列表。 Once I pull that list O pipe it into a variable and then do a search on that variable for any files that end with .pst. 一旦我拉出该列表,就将其输入变量,然后对该变量进行搜索,查找以.pst结尾的任何文件。 Once the search is complete if there were results from the search a file should be created with the FUllname"path" of each file and the computer name should be used for naming the file. 一旦搜索完成,如果搜索结果,则应使用每个文件的FUllname“路径”创建文件,并且应使用计算机名称来命名文件。 If there are no results form the search the file would be empty but the filename should still be named after t he computer. 如果搜索没有结果,则文件将为空,但文件名仍应以计算机命名。 I believe I have gotten everything correct except that I do not know how to name the file based on the computer name. 我相信我已经得到了一切正确,除了我不知道如何根据计算机名称命名文件。 Thank you for your time and help with this. 感谢您的时间和帮助。
Here is my code so far: 到目前为止,这是我的代码:

$drives=Get-WmiObject -query "SELECT * from win32_logicaldisk where 
DriveType = '3'" | select deviceid
    foreach ($drive in $drives){
        $pstfound=Get-ChildItem $drive.deviceid *.pst -recurse | select 
        fullname
        $pst+=$pstfound
        }
        IF ($pst -eq $null) {
        $pst | Out-File \\"Servername"\Searchresults\Null
        } Else {
        $pst | Out-File \\"Servername"\Searchresults\HasItems
        }

Thank you. 谢谢。 I wasn't initially planning on using the UNC path but changed it up anyways and I think that will make it easier to go through later. 我最初并没有计划使用UNC路径,但无论如何都要改变它,我认为这样可以让以后更容易完成。 I also figured out my issue for naming the file generated after the computer it ran on. 我还想出了在运行它的计算机后命名生成的文件的问题。 I just set a variable $hostname=hostname and then set the files as \\$hostname.csv 我只是设置一个变量$ hostname = hostname,然后将文件设置为\\ $ hostname.csv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM