<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();
$productCollection->addAttributeToSelect('sku');
$productCollection->addAttributeToSelect('entity_id');
$csvFile = fopen('product_ids.csv', 'w');
fputcsv($csvFile, ['SKU', 'Product ID']);
foreach ($productCollection as $product) {
fputcsv($csvFile, [$product->getSku(), $product->getId()]);
}
fclose($csvFile);
In this code, we're using the Product\CollectionFactory object to retrieve a collection of products. We then add the sku and entity_id attributes to the collection's selection. We iterate over the collection and write the SKU and product ID values to a CSV file.
Make sure to place this code in a PHP file, locate it in the root directory of your Magento installation, and run it from the command line or by accessing the file through a browser. The resulting CSV file will contain the exported SKUs and product IDs.
Remember to adjust the file permissions as needed and customize the export format according to your preferences.
I hope this meets your requirements!