Skip to content

Instantly share code, notes, and snippets.

@dansimau
Created August 11, 2022 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dansimau/10c4f7f3b0abab748c85066fefb79bf5 to your computer and use it in GitHub Desktop.
Save dansimau/10c4f7f3b0abab748c85066fefb79bf5 to your computer and use it in GitHub Desktop.
Getting PowerShell running on macOS (M1) - August 2022

Getting PowerShell running on macOS (M1) - August 2022

We need to run everything under x86 emulation, because Powershell needs opensslv1 and opensslv1 only builds under x86.

Create home directory and script to launch x86 shell:

mkdir -p $HOME/x86shell
cat <<EOF > $HOME/x86shell/.bash_profile
export PATH=$PATH:/usr/bin
export PATH=$PATH:/usr/sbin
export TERM=xterm-color
EOF

cat <<EOF > $HOME/x86shell/run.sh
#!/usr/bin/env -i HOME=$HOME/x86shell arch -x86_64 /bin/bash
bash
EOF
chmod +x $HOME/x86shell/run.sh

Start x86 shell:

cd $HOME/x86shell
./run.sh

Install homebrew (x86 version). Don't worry, it will install to /usr/local and remain separate from your arm64 version (at /opt/homebrew):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install powershell (x86 cask):

brew install powershell

The Powershell homebrew package is marked as requiring openssl@3, but Powershell is actually built to dynamically load opensslv1 (see #5561). So we need to build and install opensslv1.

Unlink the existing openssl@3:

brew unlink openssl@3
brew unlink openssl

Install opensslv1:

curl -o openssl.rb https://gist.githubusercontent.com/dansimau/2b29a6d8d8b8950b6bfae1f8235e1da1/raw/e3c30e96702a8e507a29ebbfafbede2bee07a63e/openssl.rb && brew install ./openssl.rb

Launch powershell:

pwsh

Install required modules (do these line by line, as they are interactive):

Install-Module -Name ExchangeOnlineManagement
Install-Module -Name PSWSMan
Install-Module -Name AzureAD

Test by logging into Exchange (it will open a browser window to authenticate):

Connect-ExchangeOnline

If successful you will see:

PS /private/tmp> Connect-ExchangeOnline

----------------------------------------------------------------------------
The module allows access to all existing remote PowerShell (V1) cmdlets in addition to the 9 new, faster, and more reliable cmdlets.

|--------------------------------------------------------------------------|
|    Old Cmdlets                    |    New/Reliable/Faster Cmdlets       |
|--------------------------------------------------------------------------|
|    Get-CASMailbox                 |    Get-EXOCASMailbox                 |
|    Get-Mailbox                    |    Get-EXOMailbox                    |
|    Get-MailboxFolderPermission    |    Get-EXOMailboxFolderPermission    |
|    Get-MailboxFolderStatistics    |    Get-EXOMailboxFolderStatistics    |
|    Get-MailboxPermission          |    Get-EXOMailboxPermission          |
|    Get-MailboxStatistics          |    Get-EXOMailboxStatistics          |
|    Get-MobileDeviceStatistics     |    Get-EXOMobileDeviceStatistics     |
|    Get-Recipient                  |    Get-EXORecipient                  |
|    Get-RecipientPermission        |    Get-EXORecipientPermission        |
|--------------------------------------------------------------------------|

To get additional information, run: Get-Help Connect-ExchangeOnline or check https://aka.ms/exops-docs

Send your product improvement suggestions and feedback to exocmdletpreview@service.microsoft.com. For issues related to the module, contact Microsoft support. Don't use the feedback alias for problems or support issues.
----------------------------------------------------------------------------

PS /private/tmp> 

Troubleshooting

Installing opensslv1 fails with Errno::EACCES: Permission denied

This appears to happen as Homebrew x86 installs itself using sudo and then your own user cannot write to the logs directory, e.g.:

Error: An exception occurred within a child process:
  Errno::EACCES: Permission denied @ dir_s_mkdir - /var/folders/sc/rcd0dtvx41n7lptggpq0nxzr0000gn/T/tmp.IervRAEv/Library/Logs

You can fix it by running chown on this directory, e.g.:

sudo chown -R dan /var/folders/sc/rcd0dtvx41n7lptggpq0nxzr0000gn/T/tmp.IervRAEv/Library

You'll need to replace the temp directory name above with the one in your own output.

opensslv1 fails to link with Directory not empty or Refusing to link macOS provided/shadowed software: openssl

On my machine, which already had an x86 version of Homebrew, I got an error because /usr/local/opt/openssl was not empty:

Error: Directory not empty @ dir_s_rmdir - /usr/local/opt/openssl

My solution was to remove this directory and manually re-link:

mv /usr/local/opt/openssl /usr/local/opt/openssl.old
ln -s /usr/local/Cellar/openssl/1.0.2t /usr/local/opt/openssl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment