# AZ-104 - Administration - Azure CLI and Powershell

##### [Install PowerShell on Windows, Linux, and macOS](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.4&viewFallbackFrom=powershell-7.1)

##### [How to install the Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli)

[Commands](https://github.com/BrentenDovey-ACG/AZ-104_Azure_Administrator/blob/95a62b8af178794ca2c6ebf8a19f33740a61f4e8/S02_Basic_Prerequisites_of_Azure_Administration/L03_Using_Azure_CLI_and_PowerShell/commands.txt)

##### What is the Azure CLI

- Its a command-line utility for managing azure resources
- Crate and manage resources without logging to the azure portal
- Create scripts to automate tasks

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/MMItli9d3bQQIIyC-image.png)

##### What is Azure PowerShell

- Its a set of cmdlets for managing Azure resources
- Create and manage resource s without logging into the azure portal
- Create scripts to automate tasks.

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/JK3PLdYbnKm6SUNG-image.png)

##### Cloud Shell

First we need to create a Cloud Shell

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/l2F7gayF5mj6rB1c-image.png)

Select Bash or Powershell

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/7TPnbKj9d4eABNwa-image.png)

Go to Advanced settings

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/YqjyVRkYI25CXVf0-image.png)

Select a random storage account name and a file share name then click on create storage

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/0dlFYXO4q8ZXkZVk-image.png)

if you get this error its more likely your storage account name its already in use, use alphanumeric

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/uH4r9ZuJy5UoBZ6N-image.png)

Done, you can switch between Powershell and Bash using the drop down menu on the left

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/xSgJYBT1LPmBlbvN-image.png)

Here we can run AZ CLI commands

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/jVyzDr2vjiu2oJ9y-image.png)

And here is using the powershell

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/9YNPdyK6se3s99y7-image.png)

We can save objects to variables

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/KAWBAKUxzFv2jYxS-image.png)

To create a virtual machine from Azure CLI

![image.png](https://wiki.tinod.net/uploads/images/gallery/2024-02/scaled-1680-/nBEC3mzyL0zHubwI-image.png)

```powershell
PS /home/cesar> get-cloudDrive                                                                                                        

FileShareName      : random1fileshare
FileSharePath      : //random1storage4.file.core.windows.net/random1fileshare
MountPoint         : /home/cesar/clouddrive
Name               : random1storage4
ResourceGroupName  : DefaultResourceGroup-CUS
StorageAccountName : random1storage4
SubscriptionId     : 33d9a849-c6f5-455d-b9e4-ef89b317fcec

PS /home/cesar> get-azresource | format-Table              

Name                                                      ResourceGroupName        ResourceType                             Location
----                                                      -----------------        ------------                             --------
DefaultWorkspace-33d9a849-c6f5-455d-b9e4-ef89b317fcec-CUS DefaultResourceGroup-CUS Microsoft.OperationalInsights/workspaces centralus
random1storage4                                           DefaultResourceGroup-CUS Microsoft.Storage/storageAccounts        eastus
NetworkWatcher_eastus                                     NetworkWatcherRG         Microsoft.Network/networkWatchers        eastus

PS /home/cesar> 
```