Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Powershell & CACLS

$
0
0

Howdy, folks!
I am writing a script that moves users from an Active Directory OU to another OU.
In the process, it also creates a home directory for them.

What I have so far is a way to get a list of all of the users in an OU and throw them into a list.

Get-ADUser -Filter {Description -notlike "Group"} -Searchbase "OU=New,DC=my,DC=test,DC=env" -properties * | % { '{0,10}' -f $_.sAMAccountName}  | Out-File $Output

$list = Get-Content $Output

Then I have a thing that says:

foreach ($usr in $list)
                                {
Get-ADUser $usr | Move-ADObject -TargetPath 'OU=Other,DC=my,DC=test,DC=env'
New-Item -ItemType directory -Path \\fileshare\Users\$usr
icacls \\fileshare\Users\$usr /grant $usr:(WD,RA,D)  
Set-ADUser $usr -homedirectory \\fileshare\Users\$usr -homedrive Y:                    net user $usr /active:yes /passwordreq:yes /domain 
                        
                                }

So far, the only error that is generated comes from ICACLS, it says Invalid parameter WD:

The term 'WD' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was includ
ed, verify that the path is correct and try again.
At C:\scripts\NewPeopleImport-Daily.ps1:50 char:67
+                         icacls \\fileshare\Users\$usr /grant $usr:(WD <<<< ,RA,D) 
    + CategoryInfo          : ObjectNotFound: (WD:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Any help would be greatly appreciated!


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>