问题
I am having a weird problem using Powershell and setting a HomeDirectory via the cmdlet
Set-ADUser -Identity "user" -HomeDirectory "\\fileserver\home$\user"
Even though the cmdlet is working and setting the values in the AD, the necessary folder on the fileserver "\fileserver\home$\user" will not be created.
I have also unsuccessfully tried the same with the initial creation
New-ADUser -Name "user" -HomeDirectory "\\fileserver\home$\user"
I have started the Powershell on the Exchange server as domain-admin via UAC and imported the module ActiveDirectory via
Import-Module ActiveDirectory
Instead of using the UNC-path with NetBIOS-hostnames I also tried the FQDN \fileserver.domain.local\ and also the ip adrress \ip\
If I am using the cd command to enter the UNC-path via Powershell, it does also work, I can also create directories.
cd \\fileserver\home$
mkdir test_dir
Still, the directory will not be created. If I am using the AD GUI, and try to alter the HomeDirectory-path, the folder will be created.
Any hints? Many thanks PS: 2008R2 x64, Exchange 2010, 1x Exchange, 1x AD controller, 1x fileserver
回答1:
It is worth mentioning the following from Hey, Scripting Guy! Blog
Remember, all we have done is edit a field in Active Directory. The file system on the foreign server has no clue about the information presented within Active Directory. When you edit those fields in the GUI, the user folder and permissions are provisioned as a function of the code within that GUI interface—they are not a function of Active Directory.
Much like Paul suggested I think you just need to create the folder yourself. Linked in that article is information about setting permissions for the file share as well. I imagine you already have that done.
NEW-ITEM –path "\\fileserver\home$\user" -type directory -force
回答2:
This is the best way to do this will be to create home folder for all users if doesn't exist. Create a schedule task with event id 4720 to do this automatically
Connect home folder path and drive letter.
Get-ADUser -filter * | % { Set-ADUser $_ -HomeDrive "H:" -HomeDirectory ('\\server\home$\' + $_.SamAccountName) }
create home folders for each users:-
ForEach( $User in (Get-ADUser -filter * | if( -not ( -HomeDrive "H:" -HomeDirectory ('\\server\home$\' + $_.SamAccountName) )
来源:https://stackoverflow.com/questions/26592223/powershell-homedirectory-not-created-on-fileserver-filesystem