sthildas
Members-
Posts
30 -
Joined
-
Last visited
Reputation
0 NeutralAbout sthildas

-
Eventually got this working $userhomes = Get-ChildItem "D:" | where {$_.Attributes -like '*Directory*'} foreach($userhome in $userhomes) { $exclude = "Documents" $movesource = "D:" + $userhome.Name $movedest = "D:"+ $userhome.Name +"\Documents" $autodest = "D:"+ $userhome.Name +"\Documents"+"\Autorecovery" $testpath = "D:"+ $userhome.Name +"\Desktop" $Search = "OU=Users,DC=domain,DC=co,DC=uk" $Users = Get-ADUser -Filter * -SearchBase $Search # Test if Documents folder exists, create folder if it doesnt exist If (Test-Path $movedest) { Write-Host Documents folder exists for $($userhome) # Test if Autorecovery folder exists, create folder if it doesnt exist If (Test-Path $autodest) { Write-Host Autorecovery folder exist for $($userhome) # Move Documents to new location If (Test-Path $testpath) { Get-Childitem -path $movesource -exclude $exclude | Move-Item -Dest $movedest Get-ChildItem -Path $movesource -Exclude "Documents" | ? {$_.PSIsContainer} |Remove-Item -Recurse -force Write-Host Documents being moved for $($userhome) -ForegroundColor Yellow } else { Write-Host Documents already moved for $($userhome) } } else { # Create the Autorecovery folder and set hidden attribute Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents\Autorecovery" | %{$_.Attributes="hidden"} Write-Host Autorecovery folder being created for $($userhome) -ForegroundColor Green # Move Documents to new location If (Test-Path $testpath) { Get-Childitem -path $movesource -exclude $exclude | Move-Item -Dest $movedest Get-ChildItem -Path $movesource -Exclude "Documents" | ? {$_.PSIsContainer} |Remove-Item -Recurse -force Write-Host Documents being moved for $($userhome) -ForegroundColor Yellow } else { Write-Host Documents already moved for $($userhome) } } } else { # Create the Documents folder Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents" Write-Host Documents folder being created for $($userhome) -ForegroundColor Green # Check that Documents folder now exists If (Test-Path $movedest) { Write-Host Documents folder now exists for $($userhome) -ForegroundColor Magenta Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents\Autorecovery" | %{$_.Attributes="hidden"} # Test if Autorecovery folder now exists If (Test-Path $autodest) { Write-Host Autorecovery folder Created for $($userhome) -ForegroundColor Green # Move Documents to new location If (Test-Path $testpath) { Get-Childitem -path $movesource -exclude $exclude | Move-Item -Dest $movedest Get-ChildItem -Path $movesource -Exclude "Documents" | ? {$_.PSIsContainer} |Remove-Item -Recurse -force Write-Host Documents being moved for $($userhome) -ForegroundColor Yellow } else { Write-Host Documents already moved for $($userhome) } } else { # Create the Autorecovery folder and set hidden attribute Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents\Autorecovery" | %{$_.Attributes="hidden"} Write-Host Autorecovery folder being created for $($userhome) -ForegroundColor Green # Check if Autorecovery folder exists If (Test-Path $autodest) { Write-Host Autorecovery folder now exists for $($userhome) -ForegroundColor Magenta # Move Documents to new location If (Test-Path $testpath) { Get-Childitem -path $movesource -exclude $exclude | Move-Item -Dest $movedest Get-ChildItem -Path $movesource -Exclude "Documents" | ? {$_.PSIsContainer} |Remove-Item -Recurse -force Write-Host Documents being moved for $($userhome) -ForegroundColor Yellow } else { Write-Host Documents already moved for $($userhome) } } else { Write-Host ERROR Autorecovery folder still does not exist for $($userhome) -ForegroundColor Red } } } else { Write-Host ERROR Documents folder still does not exist for $($userhome) -ForegroundColor Red } } } # Set user new home folder path Get-ADUser -Filter * -SearchBase "OU=Users,DC=domain,DC=co,DC=uk" | Foreach-Object{ $sam = $_.SamAccountName Set-ADuser -Identity $_ -HomeDrive "H:" -HomeDirectory "\\server\homefolders$\$sam\Documents" Write-Host Home folder set for ($_.SamAccountName) -ForegroundColor Yellow }
-
Hi I am tryng to create a script that will move all our users HomeFolders to a subfolder called "Documents". It will create the documents folder if it does not exist and then move the contents of the users home folder to the documents folder. It will then create an "Autorecovery" folder as a sub folder of "Documents". To test this I have removed the option to carry out the move task and I am first trying to get the script to test if the "Documents" folder already exist and if not then it should create the folder. The test should output a write-host that either says the document does or doesnt exist with the user name. When I run this and look at the users that the script says have a documents folder, some do and some dont. The same goes for the ones that the script says dont have a documents folder. $userhomes = Get-ChildItem "D:" | where {$_.Attributes -like '*Directory*'} foreach($userhome in $userhomes) { $exclude = "Documents" $movesource = "D:" + $userhome.Name $movedest = "D:"+ $userhome.Name +"\Documents" $autodest = "$movedest\Autorecovery" $Search = "OU=Users,DC=domain,DC=com" $Users = Get-ADUser -Filter * -SearchBase $Search $users | % { # Test if Documents folder exists, create folder if it doesnt exist If (Test-Path $movedest) { Write-Host Documents folder exists for ($_.SamAccountName) -ForegroundColor Red } else { # Create the Documents folder # Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents" Write-Host Documents folder being created for ($_.SamAccountName) -ForegroundColor Green } # Test if Autorecovery folder exists, create folder if it doesnt exist If (Test-Path $autodest) { Write-Host Documents and Autorecovery folder exist for ($_.SamAccountName) -ForegroundColor Red } else { # Create the Autorecovery folder and set hidden attribute # Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents\Autorecovery" | %{$_.Attributes="hidden"} Write-Host Autorecovery folder being created for ($_.SamAccountName) -ForegroundColor Green } # Move Documents to new location if Documents folder exists If (Test-Path $autodest) { # Get-Childitem -path $movesource -exclude $exclude | Move-Item -Dest $movedest Write-Host Documents being moved for ($_.SamAccountName) -ForegroundColor Green # Set user new home folder path Get-ADUser -Filter * -SearchBase $Search | Foreach-Object{ $sam = $_.SamAccountName Set-ADuser -Identity $_ -HomeDrive "H:" -HomeDirectory "\\server\share\$sam\Documents" } else { Write-Host Autorecovery folder does not exist for ($_.SamAccountName) -ForegroundColor Red } } } }
-
Hi sorry, I got distracted before I added my powershell script and the post uploaded.
-
Hi I am tryng to create a script that will move all our users HomeFolders to a subfolder called "Documents". It will create the documents folder if it does not exist and then move the contents of the users home folder to the documents folder. It will then create an "Autorecovery" folder as a sub folder of "Documents". To test this I have removed the option to carry out the move task and I am first trying to get the script to test if the "Documents" folder already exist and if not then it should create the folder. The test should output a write-host that either says the document does or doesnt exist with the user name. When I run this and look at the users that the script says have a documents folder, some do and some dont. The same goes for the ones that the script says dont have a documents folder. $userhomes = Get-ChildItem "D:" | where {$_.Attributes -like '*Directory*'} foreach($userhome in $userhomes) { $exclude = "Documents" $movesource = "D:" + $userhome.Name $movedest = "D:"+ $userhome.Name +"\Documents" $autodest = "$movedest\Autorecovery" $Search = "OU=Users,DC=domain,DC=com" $Users = Get-ADUser -Filter * -SearchBase $Search $users | % { # Test if Documents folder exists, create folder if it doesnt exist If (Test-Path $movedest) { Write-Host Documents folder exists for ($_.SamAccountName) -ForegroundColor Red } else { # Create the Documents folder # Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents" Write-Host Documents folder being created for ($_.SamAccountName) -ForegroundColor Green } # Test if Autorecovery folder exists, create folder if it doesnt exist If (Test-Path $autodest) { Write-Host Documents and Autorecovery folder exist for ($_.SamAccountName) -ForegroundColor Red } else { # Create the Autorecovery folder and set hidden attribute # Get-Item -path $movesource | New-Item -ItemType Directory -Path "$movesource\Documents\Autorecovery" | %{$_.Attributes="hidden"} Write-Host Autorecovery folder being created for ($_.SamAccountName) -ForegroundColor Green } # Move Documents to new location if Documents folder exists If (Test-Path $autodest) { # Get-Childitem -path $movesource -exclude $exclude | Move-Item -Dest $movedest Write-Host Documents being moved for ($_.SamAccountName) -ForegroundColor Green # Set user new home folder path Get-ADUser -Filter * -SearchBase $Search | Foreach-Object{ $sam = $_.SamAccountName Set-ADuser -Identity $_ -HomeDrive "H:" -HomeDirectory "\\server\share\$sam\Documents" } else { Write-Host Autorecovery folder does not exist for ($_.SamAccountName) -ForegroundColor Red } } } }
-
Hi I have a script that I am working on to export a users mailbox to PST if the mailbox PST does not already exist based on the users OU. I am running this on our Exchange 2013 server and I want to eventually run this as a sceduled task. I have created a profile.ps1 and placed this in "C:\Windows\System32\Windows Powershell\V1.0", it contains: . "C:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1" Connect-ExchangeServer -Auto I can right click my "ArchiveMailbox.ps1" and run with powershell and it will export every users mailbox that is in the oU, what I want is to add a check to only export the mailbox if the mailbox has not already been exported. If I try to run this from task scheduler it does nothing. Start a Program "powershell.exe" Argument "C:\Scripts\ArchiveMailbox.ps1" Here is my script # Variables $Users = Get-Mailbox -OrganizationalUnit $OU $OU = "{doman}/{path}" $filepath = "\\filesrv1\archive$\PST" $TestPath = $FilePath+($_.Alias)+".pst" $FileExists = Test-Path $TestPath # Move leavers home folder to Archive share $users | % { if ($FileExists -eq $false) { Write-Host "File does not exist" } Else { New-MailboxExportRequest -Mailbox $_.Alias -FilePath ($FilePath+($_.Alias)+".pst") -ExcludeFolders "#SentItems#", "#Drafts#", "#DeletedItems#", "#JunkEmail#" -ExcludeDumpster } }
-
Thanks very much, it works great. I have applied the same logic or what I believe to be the same logic to my PST archive. I dont want it to export the mailboxes to PST if the PST file already exists so I added an if statement so that it would check to see if the PST file existed and if it did then it wouldnt run. # Variables $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange.domain.co.uk/PowerShell/ -Authentication Kerberos $OU = "domain.co.uk/leavers/staffleavers" $filepath = "\\server\archive$\PST" # Move leavers email to PST on Archive share Get-Mailbox -OrganizationalUnit $OU | foreach {$Destination = $FilePath+($_.Alias)+".pst"} if (-not (Test-Path $Destination)) { Get-Mailbox -OrganizationalUnit $OU | foreach { New-MailboxExportRequest -Mailbox $_.Alias -FilePath ($FilePath+($_.Alias)+".pst")} } I am sure this could be cleaned up but it works. Again thanks for the help.
- 7 replies
-
- home folders
- leavers
-
(and 2 more)
Tagged with:
-
I have changed the script to $Search = "OU=StaffLeavers,OU=Leavers,DC=domain,DC=co,DC=uk" $movesource = "\\server\HomeFolders$\$($user.samaccountname)" $movedest = "\\server\share$" $Users = Get-ADUser -Filter {(Enabled -eq $false)} -SearchBase $Search -Properties HomeDirectory | select -property SamAccountName,homeDirectory foreach($User in $Users) { # Move leavers home folder to Archive share Move-Item -Path $movesource -Destination $movedest -force -WhatIf } This seems to find the correct users but it pulls in the same user over and over again. We have 11 users in the $Search OU and when I run the above it tries to move one user 11 times. What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". What if: Performing the operation "Move Directory" on target "Item: \\filesrv1\homefolders$\user1 Destination: \\server\share$\user1". I am still missing something? I tried with your suggestion and it works, could you help me understand why mine above still doesnt? I know I am so close.
- 7 replies
-
- home folders
- leavers
-
(and 2 more)
Tagged with:
-
Your correct this is were I'm struggling, our folder structure is \\server\share\sAMAccountName. The Get-ADUser is pulling in the correct users but I cannot get this to pass to the Move-Item and only move those users home folders. I am assuming the error lies in the $MoveSource but I dont understand why it is moving all users home folders and not just the user folders that have been selected with the Get-ADUser. I would have assumed if the $username.name wasnt being processed then it wouldnt have moved any folders and would have failed. Any help in pointing me in the right direction appreciated
- 7 replies
-
- home folders
- leavers
-
(and 2 more)
Tagged with:
-
I am trying to write a script that when users leave and are moved to a Leavers OU, a scheduled script runs and exports their email to PST, moves their Home Folder to an acrchive and clears all their custom attributes. The PST export works, the clearing of the custom attributes works but I cannot get the moving the home folders to work, any assistance would be appreciated. # Import Modules Import-PSSession $Session -AllowClobber -DisableNameChecking # Variables $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server.domain.co.uk/PowerShell/ -Authentication Kerberos $OU = "domain/leavers/staffleavers" $Search = "OU=StaffLeavers,OU=Leavers,DC=domain,DC=co,DC=uk" $filepath = "\\server\archive$\PST" $movesource = "\\server\homefolders$" + $userhome.name $movedestination = "\\server\archive$" # Move leavers email to PST on Archive share Get-Mailbox -OrganizationalUnit $OU | foreach { New-MailboxExportRequest -Mailbox $_.Alias -FilePath ($FilePath+($_.Alias)+".pst")} # Move leavers home folder to Archive share Get-ADUser -Filter * -SearchBase $Search | ForEach-Object ($_.samaccountname) { if (test-path($movesource)) { Move-Item -Path $movesource -Destination $movedestination -force } } # Clear all leavers custom attributes Get-ADUser -Filter * -SearchBase $Search | Set-ADUSer -Clear "extensionAttribute1" , "extensionAttribute2" , "extensionAttribute3" , "extensionAttribute4" , "extensionAttribute15"
- 7 replies
-
- home folders
- leavers
-
(and 2 more)
Tagged with:
-
Clickview Exchange Request: Young British and Broke
sthildas replied to sthildas's topic in AV and Multimedia Related
Thanks, downloaded now -
Clickview Exchange Request: Young British and Broke
sthildas replied to sthildas's topic in AV and Multimedia Related
Hi Pete I have searched for it but not able to find Thanks -
Clickview Exchange Request: Young British and Broke
sthildas replied to sthildas's topic in AV and Multimedia Related
Thanks Pete, appreciated -
Clickview Exchange Request: Young British and Broke
sthildas replied to sthildas's topic in AV and Multimedia Related
I think we could get plenty of offers of that, lol
