0

Something similar to $IsLinux or $IsWindows.

Doug Finke
  • 6,675
  • 1
  • 31
  • 47

3 Answers3

0

From your description, I am not sure how did you run your script. If you use Start-Job to run the PowerShell script as a background job, you could use Get-Job to see the State.

Start-Job -FilePath ./GetDate.ps1  
Get-Job

enter image description here

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • Why would I do a `start-job` every time I ran a script in the Azure Console? What if I wanted to use the same script locally and in the console but save the data in a different place? I don't want a hack, I want a scalable, portable and testable solution. – Doug Finke Jan 17 '20 at 20:31
0

This is an old, but I had the same question and found this environment variable that works for my purposes. I'm not sure if there's another "official" way though.

PS> $env:AZUREPS_HOST_ENVIRONMENT
cloud-shell/1.0
RG5
  • 517
  • 1
  • 5
  • 16
-1

I would suggest running a command in a try/catch that is specific to cloud shell, if that is what you are looking for?

    try {
        $sessioninfo = Get-CloudDrive
        if ($sessioninfo) {
            Write-Host "Running in Cloud Shell mode..." -ForegroundColor Green
            $path = ($home + "/clouddrive/" + "report" + "-$(get-date -Format yyyyddMM_hhmmtt).csv")
        }   
    }
    catch {
        Write-Host "Running in local PowerShell session mode..." -ForegroundColor Yellow
        $path = "C:\localpath\report"+"-$(get-date -Format yyyyddMM_hhmmtt).csv"
    }