Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell #15

Open
nntrn opened this issue Feb 22, 2023 · 3 comments
Open

Powershell #15

nntrn opened this issue Feb 22, 2023 · 3 comments

Comments

@nntrn
Copy link
Owner

nntrn commented Feb 22, 2023

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 nntrn changed the title Powershell Snippets Powershell Apr 10, 2023
github-actions bot pushed a commit that referenced this issue Apr 10, 2023
github-actions bot pushed a commit that referenced this issue Apr 10, 2023
@nntrn
Copy link
Owner Author

nntrn commented Apr 10, 2023

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

github-actions bot pushed a commit that referenced this issue Apr 10, 2023
github-actions bot pushed a commit that referenced this issue Apr 10, 2023
@nntrn
Copy link
Owner Author

nntrn commented Apr 11, 2023

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

github-actions bot pushed a commit that referenced this issue Apr 11, 2023
@nntrn
Copy link
Owner Author

nntrn commented Apr 13, 2023

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

github-actions bot pushed a commit that referenced this issue Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant