<?php $sites_q = new \WP_Site_Query( [
    'site__not_in' => get_main_site_for_network(),
] );
$sites_for_network = $sites_q->get_sites();
if ( ! empty( $sites_for_network ) ) {
    $original_site_id = get_current_blog_id();
    foreach ( $sites_for_network as $site ) {
         /** @var $site \WP_Site */
         switch_to_blog( $site->blog_id );
         // Do stuff with the site
    }
    switch_to_blog( $original_site_id );
}