Replies: 3 comments 4 replies
-
If I'm not mistaken, PowerShell struggles to handle stderr output. A function like this can help: function Invoke-CliM365Command {
param (
[Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)]
[string]$command
)
$output = Invoke-Expression "$command 2>&1"
if ($LASTEXITCODE -ne 0) {
throw $output
}
if ($output) {
return $output | ConvertFrom-Json
}
} Then you can use it like: $sites = Invoke-CliM365Command "m365 spo site list" @martinlingstuyl, correct me if I'm wrong or forgot something 🙂 |
Beta Was this translation helpful? Give feedback.
2 replies
-
same as @martinlingstuyl I do the following in my scripts
|
Beta Was this translation helpful? Give feedback.
2 replies
-
@milanholemans @martinlingstuyl @Adam-it I will try them out to see what suits me best. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to call a CLI command from the PowerShell script like
But due to missing permissions it fails and the output is only error message
Is there any way to check if the command has failed?
Beta Was this translation helpful? Give feedback.
All reactions