powershell常用操作

创建文件
  1. New-Item -path $file_path -itemtype file
创建目录
  1. New-Item -path $dir_path -type directory

删除目录

  1. Remove-Item-Force-Recurse $dir
赋予权限
  1. $account ="Business"
  2. $Folder = D:WebSite
  3. $FileSystemRights ="FullControl"
  4. $objType =[System.Security.AccessControl.AccessControlType]::Allow
  5. $accessRule =New-ObjectSystem.Security.AccessControl.FileSystemAccessRule($account,$FileSystemRights,$objType)
  6. $acl =Get-Acl $Folder
  7. $acl.SetAccessRule($accessRule)
  8. Set-Acl-Path $Folder -AclObject $acl
访问共享文件夹
  1. $user ="admin"
  2. $passwd ="123456"
  3. net use $dir $passwd /user:$user
复制文件
  1. $files =Get-ChildItem-Path $RemotePath -Force
  2. foreach($file in $files){
  3. Copy-Item-Path $file.FullName-Destination $LocalPath -Recurse-Force
  4. }
原文地址:https://www.cnblogs.com/letong/p/4744348.html