Here are 2 quick lines of code that help you uninstall a Program:
$Prog = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -match “ProgramName”}
$Prog.Uninstall()
Reading time: 1 min
Here are 2 quick lines of code that help you uninstall a Program:
$Prog = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -match “ProgramName”}
$Prog.Uninstall()
If you need to deploy a MS Store App for example through Intune or GPO, here is my script:
First of all you need the App ID of the store app. Go to https://apps.microsoft.com/ search for the app and select it. In the URL you will see something like this: https://apps.microsoft.com/detail/9nw77489ngj0?hl=en-us&gl=US. 9nw77489ngj0 is the App ID.
Now the script:
Start-Transcript -Path “C:\3cx_msstore.log”
$appid=”9NW77489NGJ0″
winget install -e –id $appid –source msstore –accept-source-agreements –accept-package-agreements
winget upgrade –id $appid
Stop-Transcript
This quick script shows you if and where inheritance is deactivated. You can also set in the parameters how deep or how many levels inheritance is checked.
# Function to check inheritance up to the specified level
function Check-Inheritance {
param (
[string]$directoryPath,
[int]$currentLevel,
[int]$maxLevel
)
# Exit if current level exceeds max level
if ($currentLevel -gt $maxLevel) {
return
}
# Get the ACL of the directory
$acl = Get-Acl -Path $directoryPath
# Check if inheritance is disabled
if ($acl.AreAccessRulesProtected) {
Write-Output "$directoryPath - Inheritance is disabled"
} else {
#Write-Output "$directoryPath - Inheritance is enabled"
}
# Recursively check subdirectories if current level is less than max level
if ($currentLevel -lt $maxLevel) {
$subdirectories = Get-ChildItem -Path $directoryPath -Directory
foreach ($subdir in $subdirectories) {
Check-Inheritance -directoryPath $subdir.FullName -currentLevel ($currentLevel + 1) -maxLevel $maxLevel
}
}
}
# Function to check inheritance up to the specified level
function Check-Inheritance {
param (
[string]$directoryPath,
[int]$currentLevel,
[int]$maxLevel
)
# Exit if current level exceeds max level
if ($currentLevel -gt $maxLevel) {
return
}
# Get the ACL of the directory
$acl = Get-Acl -Path $directoryPath
# Check if inheritance is disabled
if ($acl.AreAccessRulesProtected) {
Write-Output "$directoryPath - Inheritance is disabled"
} else {
#Write-Output "$directoryPath - Inheritance is enabled"
}
# Recursively check subdirectories if current level is less than max level
if ($currentLevel -lt $maxLevel) {
$subdirectories = Get-ChildItem -Path $directoryPath -Directory
foreach ($subdir in $subdirectories) {
Check-Inheritance -directoryPath $subdir.FullName -currentLevel ($currentLevel + 1) -maxLevel $maxLevel
}
}
}
To execute the script:
Check-Inheritance -directoryPath $rootDirectory -currentLevel 1 -maxLevel 3
A follow-up on the last post here is another way to run msiexec through PowerShell.
For example, here is how you can install OCS inventory agent with some parameters. OCS is an open source inventarization system.
Start-Process -FilePath .\OCS-Windows-Agent-Setup-x64.exe -ArgumentList ‘/S /NOSPLASH /NOW /SERVER=https://inventory.ajni.it//ocsinventory /TAG=”a” /SSL=0’
References:
https://www.ajni.it/2024/04/run-msiexec-transforms-with-powershell/
It might be tricky to run msiexec mst files with PowerShell, because of the arguments that contain special characters. Here is a quick line that you might need next time you install programs with msiexec and PowerShell:
Start-Process -Wait “msiexec.exe” -ArgumentList ‘/i “path-to.msi” TRANSFORMS=”path-to-file.mst” /passive /norestart’