Windows:Powershell的使用

文章目录


零、格式化输出命令

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

返回一个安全标识符对象: FileSecurityDirectorySecurityRegistrySecurity

复制代码
[---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

对一个对象的安全标识符进行相应权限设置,涉及到的对象如下。

安全标识符: FileSecurityDirectorySecurityRegistrySecurity

参数:IdentityReferenceFileSystemAccessRule

复制代码
[-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#代码,需要用的时候查询即可,这里主要做一个记录,方便需要使用的可以代码复用。

相关推荐
小白白3616 小时前
Pixelorama怎么用?像素画绘制和动画制作入门
windows
sukalot9 小时前
windows网络适配器驱动开发-WiFiCx Wi-Fi 7 功能要求(三)
windows·驱动开发
脚踏实地皮皮晨12 小时前
003003001_Grid控件
开发语言·windows·算法·c#·visual studio
ziguo112212 小时前
Windows API MessageBox 函数详解
c语言·c++·windows·visualstudio
sukalot13 小时前
windows网络适配器驱动开发-WiFiCx Wi-Fi 7 功能要求(二)
windows·驱动开发
山河不见老15 小时前
【Cursor 、Qoder安装问题】Cursor 、Qoder安装卡在“正在准备安装”问题排查及解决
人工智能·windows·编辑器
love530love16 小时前
Windows 原生编译 SGLang(2/8):三铁证判定可行 + --no-deps 外科手术式安装
windows·sglang
love530love17 小时前
Windows 原生编译 SGLang(4/8):环境关——VS 版本、venv 顺序、CUDA 多版本、生成器缓存
windows·缓存·sglang
2601_9623649717 小时前
Windows Hello 密钥生命周期科普:注册、鉴权、重置加密逻辑
windows·电脑
脚踏实地皮皮晨17 小时前
003003002_WPF Grid 基类官方类定义逐行深度解析
开发语言·windows·算法·c#·wpf·visual studio