Appearance
PowerShell 常用命令
1. 获取某文件夹下所有文件的 MD5
PowerShell
Get-ChildItem -Path "E:\" -Recurse | ForEach-Object {
if (-not $_.PSIsContainer) {
$hash = Get-FileHash -Path $_.FullName -Algorithm MD5
Write-Output "$($hash.Hash) $($hash.Path)"
}
}1
2
3
4
5
6
2
3
4
5
6
2. 获取文件的产品版本
PowerShell
(Get-Item "YOUR_FILE_PATH").VersionInfo | Select-Object ProductVersionPowerShell
PS C:\Users\UserName> (Get-Item "YOUR_FILE_PATH").VersionInfo | Select-Object ProductVersion
ProductVersion
--------------
2.0.8682.241521
2
3
4
5
2
3
4
5
3. 批量给文件设置控制权限
PowerShell
$FolderPath = "C:\path\to\folder"
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
"NT SERVICE\MSSQLSERVER",
"FullControl",
"Allow"
)
$FolderAcl = Get-Acl $FolderPath
$FolderAcl.SetAccessRule($AccessRule)
Set-Acl $FolderPath $FolderAcl
Get-ChildItem $FolderPath -Recurse | ForEach-Object {
$FilePath = $_.FullName
$FileAcl = Get-Acl $FilePath
$FileAcl.SetAccessRule($AccessRule)
Set-Acl $FilePath $FileAcl
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17