I won't go into detail about the batch process. It should be enough to know that you can run a script through the File > Automate > Batch...
by first making a Photoshop Action, where you open a script file: File > Scripts > Browse...
. Obviously you can also do more things within that same Action.
I'm not exactly confident I understand what you want, so I'm posting 2 scripts. Make a new .jsx
file where you paste one of these scripts and use that in the action.
These both work with portrait and landscape images.
Image to square - Shrink script.jsx:

var rUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var docWidth = doc.width;
var docHeight = doc.height;
var newSize = docWidth > docHeight ? docHeight : docWidth;
app.activeDocument.resizeCanvas( newSize, newSize, AnchorPosition.MIDDLECENTER );
app.preferences.rulerUnits = rUnits;
Image to square - Grow script.jsx:

The extended background color comes from the background color set in the toolbar.
var rUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var docWidth = doc.width;
var docHeight = doc.height;
var newSize = docWidth > docHeight ? docWidth : docHeight;
app.activeDocument.resizeCanvas( newSize, newSize, AnchorPosition.MIDDLECENTER );
app.preferences.rulerUnits = rUnits;