I am developing a C# application and using the following PowerShell script to create a new Group Policy Object (GPO) and link it to a specified domain or organizational unit. The script works fine for creating the GPO and linking it, but I am struggling with adding a software installation policy to this GPO. Specifically, I want to assign the installation of an MSI package located at $MsiPath
(in a shared folder).
Here’s the script I have so far:
[string]$GpoName,
[string]$DomainName,
[string]$OuPath,
[string]$MsiPath
)
# Load the Group Policy module
Import-Module GroupPolicy
try {
# Create a new GPO and link it to the OU
$gpo = New-GPO -Name $GpoName -Domain $DomainName
New-GPLink -Name $GpoName -Target $OuPath -LinkEnabled Yes -Order 1
# Get the GPO's GUID
$gpoGuid = (Get-GPO -Name $GpoName -Domain $DomainName).Id
# I need help with the following part:
# Create a new software installation policy to install the MSI package at $MsiPath
}
catch {
Write-Host 'An error occurred: ' + $_
}
How can I update my script to add a software installation policy to the newly created GPO?
Or any C# module that can help?
Any assistance or code examples would be greatly appreciated!
Chanaka Ramanayake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.