文件服務之powershell應用

#批量建立用戶賬號
$password = convertto-securestring -String "123456" -AsPlainText –Force
Import-Csv c:\user.csv | %{New-ADUser -Name $_.name -SamAccountName $_.SamAccountName -Department $_.department -Title $_.title -officephone $_.officephone -userprincipalname $_.userprincipalname -givenname $_.givenname -surname $_.surname -displayname $_.name -accountpassword $password -enabled $true -Path "ou=temp,dc=itprocn,dc=com"}
attachimg.gif20131016_0268fb2db867d08b7343gsvnvPJQ4Tr


#批量建立羣組
Import-Csv "c:\group.csv" | ForEach-Object {New-ADGroup -Name $_.name -SamAccountName $_.samaccountname -Description $_.description -GroupScope $_.groupscope -GroupCategory $_.groupcategory -Path "ou=group,ou=itprocn,dc=itprocn,dc=com"}
20131016_fc7ff40e0886eddc3163PdgWZE4rxQf


#把用戶加入羣組
$user = Get-ADUser -Filter {department -eq "資訊部"} -SearchBase "dc=itprocn,dc=com"
Add-ADGroupMember -identity "cn=mis,ou=group,ou=itprocn,dc=itprocn,dc=com" -Members $user
或者
Get-ADUser -Filter {department -eq "人事部"} -SearchBase "dc=itprocn,dc=com" | %{
Add-ADGroupMember -identity "cn=hr,ou=group,ou=itprocn,dc=itprocn,dc=com" -Members $($_.SamAccountName)}


#單個建立目錄
New-Item -path d:\temp -type directory
New-Item -path d:\common -type directory
New-Item -path d:\department -type directory

#建立目錄
Import-Csv C:\hr.csv |foreach{New-Item -path D:\department\hr -name $_.name -Type directory}
Import-Csv C:\mis.csv |foreach{New-Item -path D:\department\mis -name $_.name -Type directory}
Import-Csv C:\common.csv |foreach{New-Item -path D:\common -name $_.name -Type directory}
20131016_9dd673ee7b6d11d69872WJDQnaQbnUW

20131016_c3de372559de86c8e7c8qb1WfQMpA2Z


#建立共享(需要用到cmd)
net share department=d:\department /grant:everyone,full
net share common=d:\common /grant:everyone,full
net share temp=d:\temp /grant:everyone,full

#設置權限

##設置Temp權限
icacls D:\temp /inheritance:r /grant:r administrators:(oi)(ci)(f) "creator owner":(oi)(ci)(f) "domain users":(oi)(ci)(rx,m)

##設置Common權限
icacls D:\common /inheritance:r /grant:r administrators:(oi)(ci)(f) "creator owner":(oi)(ci)(f) "domain users":(rx)

import-csv C:\group.csv | % {
$name = $_.name
icacls D:\common\$name /inheritance:r /grant:r administrators:f ""$name":f"}



##設置Department權限
icacls D:\department /inheritance:r /grant:r administrators:(oi)(ci)(f) "creator owner":(oi)(ci)(f) "domain users":(rx)
icacls D:\department\* /inheritance:r /grant:r administrators:(oi)(ci)(f) "creator owner":(oi)(ci)(f) "domain users":(rx)


import-csv C:\hr.csv | % {
$name = $_.name
icacls D:\department\hr\$name /inheritance:r /grant:r administrators:f ""$name":f"}
import-csv C:\mis.csv | % {
$name = $_.name
icacls D:\department\mis\$name /inheritance:r /grant:r administrators:f ""$name":f"}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章