Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Executing gcloud command on PowerShell may fail in Windows

I use PowerShell 7.3.0 in Windows 11. I installed the Google Cloud CLI following the steps in https://cloud.google.com/sdk/docs/install,

After that, a following error occurred when I executed gcloud command.

PS > gcloud -v
C:\Users\xxxx\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\python.exe: can't find '__main__' module in ''

The gcloud.cmd is successful, but the gcloud.ps1 is not.

PS > gcloud.cmd -v
Google Cloud SDK 410.0.0
bq 2.0.81
core 2022.11.11
gcloud-crc32c 1.0.0
gsutil 5.16

PS > gcloud.ps1 -v
C:\Users\xxxx\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\python.exe: can't find '__main__' module in '

As a result of investigation, I found that an error occurred at "& "$cloudsdk_python" $run_args_array" in Cloud SDK\google-cloud-sdk\bin\gcloud.ps1. In my environment, the array $run_args_array contains an empty string, which seems to be interpreted as a Python execution target file and an error occurs.

After making the following changes, the error no longer occurs.

--- gcloud.ps1 2022-11-24 01:51:44.033534600 +0900
+++ gcloud.fixed.ps1 2022-11-24 01:51:18.693597400 +0900
@@ -110,6 +110,10 @@
}
$run_args_array += (Join-Path $cloudsdk_root_dir 'lib\gcloud.py')
$run_args_array += $args
+# The first element of the array may be an empty string, in which case the following error occurs.
+# C:\Users\xxx\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\bundledpython\python.exe: can't find '__main__' module in ''
+# Avoid this error by removing the empty string from the array.
+$run_args_array = $run_args_array -ne ""

if ($MyInvocation.ExpectingInput) {
$input | & "$cloudsdk_python" $run_args_array

How can I feed this information back to the Google Cloud CLI development team?

0 1 3,859
1 REPLY 1

Hello nobuoka,

As per Robert G in Serverfault, "There is a Github issue link wherein a bug was already filed after gcloud stopped working after updating PowerShell to 7.3. An issue is filed for Google Cloud as well. You can keep track of both links for now.

As of the moment, there are some workarounds that we could perform: