Additional Script Updates
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# Check if a specific registry key exists and a service is running
|
||||
$regPath = "HKLM:\Software\MyCompany\Settings"
|
||||
$regName = "ComplianceSetting"
|
||||
$serviceName = "MyService"
|
||||
|
||||
$regExists = Test-Path "$regPath\$regName"
|
||||
$serviceStatus = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
|
||||
|
||||
if ($regExists -and $serviceStatus.Status -eq "Running") {
|
||||
Write-Output "Compliance settings are in place."
|
||||
} else {
|
||||
Write-Output "Compliance settings are not in place."
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# Ensure the registry key is set and the service is running
|
||||
$regPath = "HKLM:\Software\MyCompany\Settings"
|
||||
$regName = "ComplianceSetting"
|
||||
$regValue = "Enabled"
|
||||
$serviceName = "MyService"
|
||||
|
||||
if (-Not (Test-Path "$regPath\$regName")) {
|
||||
New-Item -Path $regPath -Force | Out-Null
|
||||
New-ItemProperty -Path $regPath -Name $regName -Value $regValue -PropertyType String -Force | Out-Null
|
||||
} else {
|
||||
Set-ItemProperty -Path $regPath -Name $regName -Value $regValue
|
||||
}
|
||||
|
||||
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
|
||||
if ($service.Status -ne "Running") {
|
||||
Start-Service -Name $serviceName
|
||||
}
|
||||
Reference in New Issue
Block a user