文章目录
零、格式化输出命令
1、Format-List(别名:fl)
可通过管道符传递对象进行格式化输出,也可指定安全标识符对象进行格式化输出。
[---Property "String"]:可选指定文件或文件夹路径。
[-InputObject object]:指定对象进行格式化输出。
使用管道符传递对象并格式化输出。
powershell
$object=Get-Acl ".\AutoJS\1*" | fl
使用-InputObject格式化输出指定对象。
powershell
$object=Get-Acl ".\AutoJS\1*"
fl -InputObject $object
一、服务管理SC命令
二、软件管理命令
三、权限管理命令
1、Get-Acl
返回一个安全标识符对象: FileSecurity 、DirectorySecurity 、RegistrySecurity。
[---Path "String"]:可选指定文件或文件夹路径。
[-Exclude "String"]:可选指定排除项。
[-include "String"]:可选指定包含项。
获取文件夹对象的安全标识符并格式化输出!
powershell
Get-Acl "FilePath" | Format-List -Property *
powershell
Get-Acl -Path ".\AutoJS\1*" | Format-List -Property *
获取特定文件夹内部的txt文件的安全标识符并格式化输出!
powershell
Get-Acl -Path ".\AutoJS\*" -include *.txt | Format-List -Property *
获取特定文件夹内部的所有文件(但排除txt文件)的安全标识符并格式化输出!
powershell
Get-Acl -Path ".\AutoJS\*" -Exclude *.txt | Format-List -Property *
2、Set-Acl
对一个对象的安全标识符进行相应权限设置,涉及到的对象如下。
安全标识符: FileSecurity 、DirectorySecurity 、RegistrySecurity 。
[-Path String]:指定路径。
[-AclObject FileSystemAccessRule]:可选指定文件或文件夹路径。
对文件夹进行所有者设置!
powershell
$USO = Get-Acl .\USOPrivate\
$USO.SetOwner("NT SERVICE\TrustedInstaller")
$account=New-Object System.Security.Principal.NTAccount("NT SERVICE\TrustedInstaller")
$USO.SetOwner($account)
Set-Acl .\USOPrivate\ -AclObject $USO
移除文件夹的其中一条权限配置!
powershell
$FileAccessRule=New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators","FullControl","Allow")
$USO=Get-Acl .\USOPrivate\
$USO.RemoveAccessRule($FileAccessRule)
Set-Acl .\USOPrivate\ -AclObject $USO
总结
PowerShell的主要底层语言使用C#,很多基本都是C#代码,需要用的时候查询即可,这里主要做一个记录,方便需要使用的可以代码复用。