nntrn / save

https://nntrn.github.io/save/
2 stars 0 forks source link

Powershell #15

Open nntrn opened 1 year ago

nntrn commented 1 year ago

List the pending/missing Windows updates.

$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
$Updates | ConvertTo-Json -Depth 1

Source

nntrn commented 1 year ago

Copy NTFS permissions

get-acl C:\path_with_desired_permissions | set-acl C:\path_lacking_desired_permissions

# set recursively
$perm = Get-Acl C:\path_with_desired_permissions
Get-ChildItem C:\path_lacking_desired_permissions -Recurse | Set-Acl -AclObject $perm -WhatIf
nntrn commented 1 year ago

Set-Acl

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-acl?view=powershell-7.3

Example 1: Copy a security descriptor from one file to another

$DogACL = Get-Acl -Path "C:\Dog.txt"
Set-Acl -Path "C:\Cat.txt" -AclObject $DogACL

Example 2: Use the pipeline operator to pass a descriptor

Get-Acl -Path "C:\Dog.txt" | Set-Acl -Path "C:\Cat.txt"

Example 3: Apply a security descriptor to multiple files

$NewAcl = Get-Acl File0.txt
Get-ChildItem -Path "C:\temp" -Recurse -Include "*.txt" -Force | Set-Acl -AclObject $NewAcl
nntrn commented 1 year ago

Get stopped services with Automatic startup

Get-WmiObject -Class Win32_Service | Select-Object Name,State,StartMode | Where-Object {$_.State -ne 
"Running" -and $_.StartMode -eq "Auto"}

Source