Skip to main content

Server Scripte

Services starten

$services = Get-WmiObject Win32_Service
foreach ($line in $services) {
    $service = $line.displayname
    $status = $line.state
    $startup = $line.startmode
    if ($service -like "Microsoft Exchange*") {
        if (($status -eq "Stopped") -and ($startup -eq "Auto")) {
            write-host $service" needs to be started.  Starting it now."
            start-service $service
        }
    }
    if ($service -like "Active Directory Web Services") {
        if (($status -eq "Stopped") -and ($startup -eq "Auto")) {
            write-host $service" needs to be started.  Starting it now."
            start-service $service
        }
    }
}
foreach ($line in $services) {
    $service = $line.displayname
    $status = $line.state
    $startup = $line.startmode
    if ($service -like "Microsoft Exchange*") {
        get-service $service
    }
}

Services stoppen

$services = Get-WmiObject Win32_Service
foreach ($line in $services) {
    $service = $line.displayname
    $status = $line.state
    $startup = $line.startmode
    if ($service -like "Microsoft Exchange*") {
        if (($status -eq "Running") -and ($startup -eq "Auto")) {
            write-host $service" needs to be stopped.  Stopping it now."
            stop-service $service -force
        }
    }
    if ($service -like "Active Directory Web Services") {
        if (($status -eq "Running") -and ($startup -eq "Auto")) {
            write-host $service" needs to be stopped.  Stopping it now."
            stop-service $service -force
        }
    }
}
foreach ($line in $services) {
    $service = $line.displayname
    $status = $line.state
    $startup = $line.startmode
    if ($service -like "Microsoft Exchange*") {
        get-service $service
    }
}