Hello,
I need help trying to figure out how to take PST files owned by a user on a network drive. It would need to
1) Locate PST Files (This is not hard) and add to array for that user
2) Copy PST files with new name to centralized location. PST Names should be the same as the user's root H: Drive folder and something to identify (numerical value) that each one is different.
3) Set permissions on the original PST File or Delete it straight out.
The issue is that MANY or MOST users in or org have not just 1 or 2 PST files but 5 to 10 or more. I have the powershell portion of identifying the pst files but how to copy and rename them to a central location by either the folder they sit in and/or numerical value identifier eludes me.
Thanks,
Dwight
PST Find,Rename and Move
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- dwight.brookland
- Posts: 17
- Last visit: Tue Mar 26, 2024 11:24 am
Re: PST Find,Rename and Move
I would also like to include the original file name in the new file name.
Example:
Original file:
\\Server\Home\BobbyB\Outlook\bobby.pst
\\Server\Home\BobbyB\Outlook\Archive.pst
\\Server\Home\BobbyB\TermUser\DaveA\Dave.pst
\\Server\Home\BobbyB\TermUser\DaveA\Archive.pst
New File:
\\Server\IT\PSTs\BobbyB_Outlook_bobby.pst
\\Server\IT\PSTs\BobbyB_Outlook_Archive.pst
\\Server\IT\PSTs\BobbyB_DaveA_Dave.pst
\\Server\IT\PSTs\BobbyB_DaveA_Archive.pst
This way it has the ability to continually identify who the file belongs to NOW, as well as what folder it was in so we can make some level of direction when setting them up for import into the user's mailbox in Exchange Online.
Example:
Original file:
\\Server\Home\BobbyB\Outlook\bobby.pst
\\Server\Home\BobbyB\Outlook\Archive.pst
\\Server\Home\BobbyB\TermUser\DaveA\Dave.pst
\\Server\Home\BobbyB\TermUser\DaveA\Archive.pst
New File:
\\Server\IT\PSTs\BobbyB_Outlook_bobby.pst
\\Server\IT\PSTs\BobbyB_Outlook_Archive.pst
\\Server\IT\PSTs\BobbyB_DaveA_Dave.pst
\\Server\IT\PSTs\BobbyB_DaveA_Archive.pst
This way it has the ability to continually identify who the file belongs to NOW, as well as what folder it was in so we can make some level of direction when setting them up for import into the user's mailbox in Exchange Online.
- dwight.brookland
- Posts: 17
- Last visit: Tue Mar 26, 2024 11:24 am
Re: PST Find,Rename and Move
Update - How would you handle at that point assigning iterations if files are the same. Add numerical values to the end of the name with a replace value and add a n++ value to the end with .pst?
- dwight.brookland
- Posts: 17
- Last visit: Tue Mar 26, 2024 11:24 am
Re: PST Find,Rename and Move
This is conceptualization not code yet. Looking for direction or examples of how to process or grab specific pieces of a unc path or file object.. Was just looking for ideas.
Re: PST Find,Rename and Move
I recommend that you write your script and then post a specific question.
You can check if a filename is I use with "Test-Path".
help test-path -Full
CHeck the examples to see how to use the command.
You can check if a filename is I use with "Test-Path".
help test-path -Full
CHeck the examples to see how to use the command.
- dwight.brookland
- Posts: 17
- Last visit: Tue Mar 26, 2024 11:24 am
- dwight.brookland
- Posts: 17
- Last visit: Tue Mar 26, 2024 11:24 am
Re: PST Find,Rename and Move
Code: Select all
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.153
Created on: 8/15/2018 3:12 PM
Created by:
Organization:
Filename:
===========================================================================
.DESCRIPTION
PST Migration Script.
#>
$searchClasses = "UNC Search", "File Search"
$c = 1
$searchClasses | Foreach {
Write-Host $c.ToString() -NoNewLine
Write-Host " --- " -NoNewLine
Write-Host $_ -ForegroundColor Green
$c++
}
[int]$searchClass = Read-Host "Select the search class"
$choice = $searchClasses[$searchClass - 1]
Write-Host $choice -ForegroundColor Yellow
## BUILD USER FOLDER LIST ##
If ($choice -eq "UNC Search")
{
$userFilePath = Read-Host "Enter UNC Path to User Folders: (Example: \\Thermon.local\USSM\HOME)"
$destination = Reach-Host "Enter Destination Folder Path: (Excample: \\Thermon.local\USSM\HOME\PSTs)"
$UserFolders = Get-ChildItem -Path $userFilePath -Directory
$UserFolders | foreach {
$user = Get-ADUser -Identity $_ -Properties *
$homeDir = $userFilePath + "\" + $_
$filter = "*.pst"
$n = 1
$userPSTs = Get-ChildItem -Path $homeDir -Filter $filter -Recurse
$userPSTs | foreach {
$fullName = $_.FullName
$oldName = $_.Name
$newName = $_.Name
$newName = $newName.Replace(".pst", "$n.pst")
Rename-Item -NewName $newName -Path $fullName
$newName = $user.UserPrincipalName + "_" + $newName
$fullName = $fullName.Replace("$oldName", "$newName")
Rename-Item -NewName $newName -Path $fullName
$n++
}
Move-Item -Path $homeDir -Filter $filter -Destination $destination
## Create Output for PST Mapping File for O365 Import Job ##
}
Get-ChildItem -Path $destination -Filter $filter | Out-GridView
}
If ($choice -eq "File Search")
{
$File = Read-Host "Enter File Name and Path to Search: (Example: \\Thermon\USSM\ITData\PSTMigration\User_Group1.csv"
$destination = Reach-Host "Enter Destination Folder Path: (Excample: \\Thermon.local\USSM\HOME\PSTs)"
$users = Import-Csv -Path $File
$users | foreach {
$user = Get-ADUser -Identity $_.samAccountName -Properties *
$homeDir = $user.HomeDirectory
$filter = "*.pst"
$n = 1
$userPSTs = Get-ChildItem -Path $homeDir -Filter $filter -Recurse
$userPSTs | foreach {
$newName = $_.Name
$oldName = $_.Name
$fullName = $_.FullName
$newName = $newName.Replace(".pst", "$n.pst")
Rename-Item -NewName $newName -Path $fullpath
$newName = $user.UserPrincipalName + "_" + $newName
$fullName = $fullName.Replace("$oldName","$newName")
Rename-Item -NewName $newName -Path $fullName
$n++
}
Move-Item -Path $homeDir -Filter $filter -Destination $destination
## Create Output for PST Mapping File for O365 Import Job ##
}
Get-ChildItem -Path $destination -Filter $filter | Out-GridView
}
- dwight.brookland
- Posts: 17
- Last visit: Tue Mar 26, 2024 11:24 am
Re: PST Find,Rename and Move
I have updated this code a little but it does now work. I had to move the $fullName=$fullname.Replace("... ") line up to right under the first rename.