首页 > 解决方案 > GCloud powershell 命令抛出错误,但在 cmd 中工作正常

问题描述

当我通过 Windows cmd 提示运行 GCloud commannds 时,它可以工作。

但是当我通过 powershell 运行它们时,它会抛出一个红色错误,但命令会成功完成。

例如:

1) 授权

gcloud auth activate-service-account xxx@xxx-xxx.iam.gserviceaccount.com --key-file=C:\xxxxx\cred.json 

错误:

python.exe : Activated service account credentials for: [xxxx@xxxx.iam.gserviceaccount.com]
At xxxxxxxxxxxx\gcloud.ps1:117 char:3
+   & "$cloudsdk_python" $run_args_array
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Activated servi...iceaccount.com]:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

2)上传文件到存储桶

gsutil cp $outputFile gs://bucketxxx

错误:

gsutil : Copying file://N:\out\sqlserver\tag.csv [Content-Type=application/vnd.ms-excel]...
At xxxxxxx\RDS_SQLServer_ExportData_DataWarehouse.ps1:38 char:5
+     gsutil cp $outputFile gs://bucketxxx  | out-null
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Copying file://...nd.ms-excel]...:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
/ [0 files][    0.0 B/  2.8 MiB]                                                
/ [1 files][  2.8 MiB/  2.8 MiB]                                                
Operation completed over 1 objects/2.8 MiB. 

标签: powershellwindows-10gcloud

解决方案


我无法发表评论,因此在此处添加我的输入。

首先:该问题似乎仅在通过 Powershell ISE 运行时出现,而不是在通过 powershell 提示符执行时出现。

第二:这不是这样的错误,例如,当您看到自己的错误时,您会发现未指定为“已激活的服务...”之后的文本表示操作已成功执行。希望这有助于其他人在这里磕磕绊绊

python.exe : Activated service account credentials for: [xxxx@xxxx.iam.gserviceaccount.com]
At xxxxxxxxxxxx\gcloud.ps1:117 char:3
+   & "$cloudsdk_python" $run_args_array
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Activated servi...iceaccount.com]:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

推荐阅读