Hi Community,<\/p>\n
I have a powershell script to create a new user in AD. Problem is that some of our file servers are in a different domain. I can connect to another domain by using the code below amending AD attributes, but how do I add a home folder on the remote file server in a different domain? There is no ad object in the other domain but a contact is created? Have searched the web, but cannot find a solution? Can anyone help?<\/p>\n
I did though have a stab if you see below, but code is wrong… Help!<\/p>\n
Thanks in advance<\/p>\n
Enable WinRM remote administrating #Initiate<\/span> Remote PS Session to local DC Invoke-Command -Session $ps -scriptblock { import-module ActiveDirectory } New-Item -Name $sam -ItemType Directory -Path $drivepathE Hi Community,<\/p>\n I have a powershell script to create a new user in AD. Problem is that some of our file servers are in a different domain. I can connect to another domain by using the code below amending AD attributes, but how do I add a home folder on the remote file server in a different domain? There is no ad object in the other domain but a contact is created? Have searched the web, but cannot find a solution? Can anyone help?<\/p>\n I did though have a stab if you see below, but code is wrong… Help!<\/p>\n Thanks in advance<\/p>\n Enable WinRM remote administrating #Initiate<\/span> Remote PS Session to local DC Invoke-Command -Session $ps -scriptblock { import-module ActiveDirectory } New-Item -Name $sam -ItemType Directory -Path $drivepathE Welcome<\/p>\n If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n
\nSet-ItemProperty –Path HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System –Name LocalAccountTokenFilterPolicy –Value 1 -Type DWord
\nTry
\n{
\nEnable-PSRemoting -Force
\n}
\ncatch
\n{}
\n#Set<\/span> trusted hosts to your second domain controller
\nSet-Item WSMan:\\localhost\\Client\\TrustedHosts –Value s-chip.sussexdowns.ac.uk<\/a> -Force<\/p>\n
\n$ps = New-PSSession -ComputerName domain server -Credential $cred<\/p>\n<\/a>Import-Module ActiveDirectory<\/h1>\n
\nImport-PSSession -Session $ps -Module ActiveDirectory -AllowClobber -ErrorAction Stop<\/p>\n<\/a>Create folder and set ACL<\/h1>\n
\n$permissions = Get-Acl $homeshareE
\n$userpermissions = New-Object System.Security.AccessControl.FileSystemAccessRule(“domain$sam”,“FullControl”,“ContainerInherit, ObjectInherit”, “None”, “Allow”)
\n$permissions.AddAccessRule($userpermissions)
\nSet-Acl $homeshare $permissions<\/p>","upvoteCount":4,"answerCount":14,"datePublished":"2022-05-26T13:38:21.000Z","author":{"@type":"Person","name":"davidchurch7329","url":"https://community.spiceworks.com/u/davidchurch7329"},"suggestedAnswer":[{"@type":"Answer","text":"
\nSet-ItemProperty –Path HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System –Name LocalAccountTokenFilterPolicy –Value 1 -Type DWord
\nTry
\n{
\nEnable-PSRemoting -Force
\n}
\ncatch
\n{}
\n#Set<\/span> trusted hosts to your second domain controller
\nSet-Item WSMan:\\localhost\\Client\\TrustedHosts –Value s-chip.sussexdowns.ac.uk<\/a> -Force<\/p>\n
\n$ps = New-PSSession -ComputerName domain server -Credential $cred<\/p>\n<\/a>Import-Module ActiveDirectory<\/h1>\n
\nImport-PSSession -Session $ps -Module ActiveDirectory -AllowClobber -ErrorAction Stop<\/p>\n<\/a>Create folder and set ACL<\/h1>\n
\n$permissions = Get-Acl $homeshareE
\n$userpermissions = New-Object System.Security.AccessControl.FileSystemAccessRule(“domain$sam”,“FullControl”,“ContainerInherit, ObjectInherit”, “None”, “Allow”)
\n$permissions.AddAccessRule($userpermissions)
\nSet-Acl $homeshare $permissions<\/p>","upvoteCount":4,"datePublished":"2022-05-26T13:38:21.000Z","url":"https://community.spiceworks.com/t/create-home-folder-on-another-domain/833728/1","author":{"@type":"Person","name":"davidchurch7329","url":"https://community.spiceworks.com/u/davidchurch7329"}},{"@type":"Answer","text":"