{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[this doc on github](https://github.com/dotnet/interactive/tree/master/samples/notebooks/powershell)\n", "\n", "# Interact with Azure Cloud Shell from PowerShell notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Magic of the `Enter-AzShell` cmdlet" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `Enter-AzShell` cmdlet is a new addition to the `Microsoft.DotNet.Interactive.PowerShell` module.\n", "Running it will authenticate you to Azure and establish a PowerShell cloud shell session for you.\n", "After that, all subsequent code submitted from the cells are executed in that cloud shell session.\n", "\n", "When you are done with the cloud shell, just type and run `exit` from a cell to end the session, and after that, all subsequent code submitted from the cells will again be executed using the local PowerShell kernel.\n", "\n", "Let's get started with some examples!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, let's list the available cmdlets from the `Microsoft.DotNet.Interactive.PowerShell`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" } }, "outputs": [], "source": [ "Get-Command -Module Microsoft.DotNet.Interactive.PowerShell" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There you go! Now run `Enter-AzShell`." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" } }, "outputs": [], "source": [ "Enter-AzShell" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we are connected to the PowerShell Azure cloud shell session,\n", "and the code submitted from cells will run in the cloud shell session.\n", "\n", "Let's run some commands." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" } }, "outputs": [], "source": [ "cd Azure:\\\n", "dir" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" } }, "outputs": [], "source": [ "Get-AzLog -max 3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" } }, "outputs": [], "source": [ "hostname" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When you are done with using the cloud shell session, run `exit` to end the session." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" } }, "outputs": [], "source": [ "exit" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, code submitted from cells will again be executed by the local PowerShell kernel." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" } }, "outputs": [], "source": [ "hostname" ] } ], "metadata": { "kernelspec": { "display_name": ".NET (PowerShell)", "language": "PowerShell", "name": ".net-powershell" }, "language_info": { "file_extension": ".ps1", "mimetype": "text/x-powershell", "name": "PowerShell", "pygments_lexer": "powershell", "version": "7.0" } }, "nbformat": 4, "nbformat_minor": 2 }