I
I
Ismat Gayibov2021-07-26 12:22:56
PowerShell
Ismat Gayibov, 2021-07-26 12:22:56

Transferring a folder with a domain username after disabling it?

Hello. Such a task is worth it. The exchanger has folders for each domain user. You need to create a script so that when a user is disabled, the folder with the username is moved to another folder (for example, the "Trash" folder)

Found how to select disabled users

Import-Module ActiveDirectory
Get-ADUser -filter {enabled -eq $false}

There is a transfer option folders

Move-Item -Path "C:\Obmen\Operators\Petr Petrov\New Folder" -Destination "C:\Trash" It's

not clear how to link them. Like if the user has such a status "False", that such a folder would be transferred to the Trash folder.

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Morrowind, 2021-07-26
@hekkaaa

Hello.
Ismat Gayibov If I understood everything correctly, simple programming is enough to connect here. use if else.
I write the code very exemplary on the go without checking it on the machine.

$checkuser = Get-ADUser user12 -filter {enabled -eq $false}
if($checkuser){
Move-Item -Path "C:\Obmen\Операторы\user12\Новая папка" -Destination "C:\Мусор"
}
else{
 Write-host "отключенных пользователей более не найдено"
}

Judging by your questions, you have a cloud of tasks there that are not difficult on PS. If you write anything directly to my mail in the profile, I will help in any way I can.

R
Roman Bezrukov, 2021-07-26
@NortheR73

$DisabledUsers = (Get-ADUser -filter {enabled -eq $false} -Properties displayname | select displayname).displayname
foreach ($User in $DisabledUsers)
{
    $FolderPath = "C:\Obmen\Операторы\$User"
    If (Test-Path $FolderPath)
    {
        Move-Item -Path $FolderPath -Destination "C:\Мусор" -Force
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question