Git Product home page Git Product logo

azurepsdrive's Introduction

Build Status

Master Development
av-image-master av-image-dev

Introduction:

AzurePSDrive provider is a SHiPS based PowerShell provider to simplify navigation and discovery of Azure Resource Manager items. This is based on Az cmdlets. The provider allows to browse Azure resources such as Subscriptions, ResourceGroups, deployments in providers such as Compute, Network, Storage. Deployments such as VirtualMachines, StorageContainers, NetworkInterfaces, SecurityGroups, VNets, WebApps can be seamlessly discovered including useful data about these.

Usage:

Using this provider is self explanatory. You are encouraged to traverse various resources such as Compute, Network, Storage, WebApps and so on. AzurePSDrive provider shows only Az providers that have deployments such as Virtual machines, Storage Containers. This version supports only retrieving Resource Manager items.

# Authenticate to your Azure account
# Login-AzAccount

# Create a drive for Az
$driveName = 'Az'
Import-Module AzurePSDrive
New-PSDrive -Name $driveName -PSProvider SHiPS -Root AzurePSDrive#Azure

cd $driveName":"
# Discover all subscriptions associated with the account
PS Az:\> dir

Mode SubscriptionName    SubscriptionId                         TenantId                                 State
---- ----------------    --------------                         -----                                    -----
+    AutomationGroup     xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx   xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx     Enabled
+    CloudOps            xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx   xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx     Disabled
+    DevOps              xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx   xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx     Enabled

# Navigate to a subscription
PS Az:\> cd .\AutomationGroup\

# Discover the first level directory under a subscription
PS Az:\AutomationGroup> dir
Mode  Name
----  ----
+     AllResources
+     ResourceGroups
+     VirtualMachines
+     StorageAccounts
+     WebApps

# Display all Azure resources under the current subscription
PS Az:\AutomationGroup>cd .\AllResources\
PS Az:\AutomationGroup\AllResources> dir

# Search Azure resources by keyword
PS az:\AutomationGroup\AllResources> dir *foobar*

Name        ResourceType                          ResourceGroupName    Location
----        ------------                          -----------------    --------
foobar1     Microsoft.Compute/virtualMachines     foobarrg             westus
foobar2     Microsoft.Compute/virtualMachines     foobarrg             westu

# Search for all VMs
PS az:\AutomationGroup> cd .\VirtualMachines\
PS az:\AutomationGroup\VirtualMachines>dir

# Search for my VMs starting a letter j*
PS az:\AutomationGroup\VirtualMachines> dir j*
ResourceGroupName   Name    Location    VmSize           OsType    NIC      ProvisioningState  PowerState
-----------------   ----    --------    ------           ------    ---      -----------------  ----------
JRG                 jvm1    eastus      Standard_DS1_v2  Windows   jnic-1   Succeeded          deallocated
JRG                 jvm2    westus      Standard_F1s     Linux      nic-2   Succeeded          running

# Start or Stop a VM
dir jvm2 | Stop-AzVM
PS az:\AutomationGroup\VirtualMachines> dir .\jvm2 | Stop-AzVM

# Search all storage accounts under my subscription
PS az:\AutomationGroup\StorageAccounts> dir
Mode  Name
----  ----
+     myacc
+     myacc2
+     myacc3

# Navigate to a particular storage account
PS az:\AutomationGroup\StorageAccounts> cd .\myacc\
PS az:\AutomationGroup\StorageAccounts\myacc> dir

Mode  Name
----  ----
+     Blobs
+     Files
+     Tables
+     Queues

# Navigate to Azure storage file share
PS az:\AutomationGroup\StorageAccounts\myacc> cd .\Files\
PS az:\AutomationGroup\StorageAccounts\myacc\Files> dir

Name     ConnectionString
----     ----------------
share1   \\myacc.file.core.windows.net\share1;AccountName=myacc
         AccountKey=<key omitted here>
share2   \\myacc2.file.core.windows.net\share2;AccountName=myacc2
         AccountKey=<key omitted here>

# Mount to Azure file share so that you can add/delete/modify files and directories
net use z: \\myacc.file.core.windows.net\share1  /u:AZURE\myacc <AccountKey>

# Navigate to a directory
PS az:\AutomationGroup\StorageAccounts\myacc\Files> cd .\share1\
PS az:\AutomationGroup\StorageAccounts\myacc\Files\share1> dir

Mode  Name
----  ----
+     .cloudconsole
.     .hello.ps1
# Discover ResourceGroups in the Subscription
PS az:\AutomationGroup> cd .\ResourceGroups\
PS az:\AutomationGroup\ResourceGroups> dir

Mode ResourceGroupName                     Location       ProvisioningState Tags
---- -----------------                     --------       ----------------- ----
+    azexpress                             southcentralus Succeeded
+    azexpress-posh2                       southcentralus Succeeded
+    ops-WestUS                            westus         Succeeded

PS Az:\AutomationGroup\ResourceGroups> cd .\azexpress\

# Discover Providers that have deployments
PS Az:\AutomationGroup\ResourceGroups\azexpress> dir

Mode ProviderName
---- ------------
+    Microsoft.ClassicStorage
+    Microsoft.Compute
+    Microsoft.Network
+    Microsoft.Storage
+    Microsoft.Web

# Navigate to your own VMs
PS Az:\AutomationGroup\ResourceGroups\azexpress\Microsoft.Compute\virtualMachines> dir

VMName         Location ProvisioningState VMSize          OS            SKU                             OSVersion AdminUserName NetworkInterfaceName
------         -------- ----------------- ------          --            ---                             --------- ------------- --------------------
azexpress-ctr-host westus   Succeeded         Standard_DS2_v2 WindowsServer 2016-Datacenter-with-Containers latest    localadmin    azexpress-ctr

# Discover NetworkInterfaces
PS Az:\AutomationGroup\ResourceGroups\azexpress\Microsoft.Network\networkInterfaces> dir

NetworkInterfaceName Location ProvisioningState VirtualMachineName PublicIpAddressName   NetworkSecurityGroupName IsPrimary
-------------------- -------- ----------------- ------------------ -------------------   ------------------------ ---------
azexpress-ctr        westus   Succeeded         azexpress-ctr-host azexpress-ctr-host-ip azexpress-ctr-host-nsg       True

# Get WebApps information
PS Az:\AutomationGroup\ResourceGroups\azexpress\Microsoft.Web\sites> dir


SiteName                       Location   State      OutboundIpAddresses  EnabledHostInfo                                                 WebSpace
--------                       --------   -----      -------------------  ---------------                                                 --------
azexpressSite                   West US    Stopped    42.139.137.127       azexpressSite.azurewebsites.net* SSl=Disabled                  2015-WestUSwebspace
                                                      40.11.139.85         azexpressSite.scm.azurewebsites.net SSl=Disabled

azexpressSite-powershell        West US    Running    42.112.85.127        azexpressSite-powershell.azurewebsites.net* SSl=Disabled       2015-WestUSwebspace
                                                      42.139.139.85        azexpressSite-powershell.scm.azurewebsites.net SSl=Disabled




# Get ServerFarms info
PS Az:\AutomationGroup\ResourceGroups\azexpress\Microsoft.Web\serverFarms> dir

ServerFarmName  Location ProvisioningState NumberOfWorkers NumberOfSites WebSpace
--------------  -------- ----------------- --------------- ------------- --------
2015Plan        West US  Succeeded         1               5             2015-WestUSwebspace



Dependencies:

Az.Accounts, Az.Resources, Az.Compute, Az.Storage, Az.Websites and SHiPS PowerShell modules are required.

Caching:

Top level objects such as Subscriptions, Resource Groups, Resource Providers are cached to improve performance. Use dir -Force to refresh from Azure service. However, leaf level objects such as Virtual Machines, Network Interfaces, WebSites are not cached, since these items can have a smaller life cycle.

Server side filtering using Az ODataQuery

Supports performing server side filtering using $filter ODataQuery semantics. Simply use dir -Filter option when retrieving items.

Supported Az Provider Types in format.ps1xml:

ProviderType Name FullType
Microsoft.Compute virtualMachines Microsoft.Compute.virtualMachines
Microsoft.Compute virtualMachines/extensions Microsoft.Compute.virtualMachines.extensions
Microsoft.Compute availabilitySets Microsoft.Compute.availabilitySets
Microsoft.Network networkInterfaces Microsoft.Network.networkInterfaces
Microsoft.Network publicIPAddresses Microsoft.Network.publicIPAddresses
Microsoft.Network virtualNetworks Microsoft.Network.virtualNetworks
Microsoft.Network networkSecurityGroups Microsoft.Network.networkSecurityGroups
Microsoft.Network routeTables Microsoft.Network.routeTables
Microsoft.Storage storageAccounts Microsoft.Storage.storageAccounts
Microsoft.ClassicStorage storageAccounts Microsoft.ClassicStorage.storageAccounts
Microsoft.Web sites Microsoft.Web.sites
Microsoft.Web serverfarms Microsoft.Web.serverfarms

azurepsdrive's People

Contributors

alexandair avatar cormacpayne avatar hemantmahawar avatar jianyunt avatar mirichmo avatar miyanni avatar raghushantha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azurepsdrive's Issues

dir -recurse throws InvalidFilterInQueryString error

Steps to reproduce

  • Open PowerShell in Cloud Shell
  • cd to a resource group, e.g., Azure:<Subscription Name>\ResourceGroups<resource group name>
  • Try to filter for some name recursively, e.g: dir -Filter PSCloud -Recurse
PS Azure:\<Subscription Name>\ResourceGroups\<resource group name>> dir

    Directory: Azure:\<subscription name>\ResourceGroups\<resource group name>

Mode ProviderName
---- ------------
+    Microsoft.Automation
+    Microsoft.Compute
+    Microsoft.Network
+    Microsoft.Storage

PS Azure:\<Subscription Name>\ResourceGroups\<resource group name>> dir -Filter "*PSCloud*" -Recurse

Expected behavior

no error

Actual behavior

InvalidFilterInQueryString error

dir : InvalidFilterInQueryString : Invalid $filter '(resourceType EQ 'Microsoft.Automation/automationAccounts') AND
(substringof(Name, *PSCloud*.Replace('*', '')) eq true)' specified in the query string.
At line:1 char:1
+ dir -Filter  *PSCloud* -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (SHiPS:String) [Get-ChildItem], Exception
    + FullyQualifiedErrorId : InvalidFilterInQueryString,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceCmdlet,Microsoft.PowerShell.Commands.GetChildItemCommand

Environment data

$env:ACC_VERSION:  master_20171021.1

Get-Module SHiPS

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.3.0      SHiPS

Get-Module AzurePSDrive

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.6.0      AzurePSDrive

Empty siteconfig property under Webapp directory

A user reported:

From Thom Schumacher
When viewing web applications in my subscription I the property for SiteConfig is empty. I would think that that would be the same value as:
Get-AzureRmWebAppSlot -name webapp -ResourceGroupName myres -slot ‘production’
In the provider my drivename is AZ.
cd az:\mysub\webapps
(gci *webapp).siteconfig
(gci *webapp).sitename — this is valid and has data

CLoudShell Version

PS Azure:\> dir env:acc_version

ACC_VERSION master_20171006.3

Modules

4.4.0 AzureRM
3.4.0 AzureRM.Profile

Module gives error when creating New-PSDrive

When trying to create a new PSDrive I get an error:

New-PSDrive : The following error occurred while loading the extended type data file: Error in TypeData 
...
InvalidOperation: (:) [New-PSDrive], RuntimeException

Both depended modules are up to date:

ModuleType Version    Name              
---------- -------    ----              
Script     5.6.0      AzureRM.Profile   
Script     6.9.0      AzureRM           

Any ideas how to solve this?

Error message should be more helpful when you are not authenticated to Azure

This is the user experience if you want to browse Azure: drive before you authenticate to Azure:

PS C:\WINDOWS\system32> cd azure:
PS Azure:\> dir
dir : Unable to obtain tenant for the account. Check your subscription to ensure there is atleast one tenant
At line:1 char:1
+ dir
+ ~~~
    + CategoryInfo          : InvalidResult: (Microsoft.PowerShell.SHiPS.SHiPSProvider:SHiPSProvider) [Get-ChildItem],
   RuntimeException
    + FullyQualifiedErrorId : GetChildItems,Microsoft.PowerShell.Commands.GetChildItemCommand

dir : One or more errors occurred.
At line:1 char:1
+ dir
+ ~~~
    + CategoryInfo          : InvalidResult: (Microsoft.PowerShell.SHiPS.SHiPSProvider:SHiPSProvider) [Get-ChildItem],
   AggregateException
    + FullyQualifiedErrorId : GetChildItems,Microsoft.PowerShell.Commands.GetChildItemCommand

dir : One or more errors occurred.
At line:1 char:1
+ dir
+ ~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], AggregateException
    + FullyQualifiedErrorId : System.AggregateException,Microsoft.PowerShell.Commands.GetChildItemCommand

Those error messages are not very helpful and user-friendly. It would be better to mention missing to Add-AzureRmAcoount (or its alias Login-AzureRmAccount). Even better would be to warn (to prevent a later error) a user about missing authentication when they import AzurePSDrive module or cd into Azure: drive.

Login-AzureRM in Test.psm1 fails due to potential invalid password?

See PR checkin test run results:

https://ci.appveyor.com/project/PowerShell/azurepsdrive/build/1.1.3.85

ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
1565
At C:\projects\azurepsdrive\tests\test.psm1:97 char:52
1566
+     $secureString = ConvertTo-SecureString -String $password -AsPlain ...
1567
+                                                    ~~~~~~~~~
1568
    + CategoryInfo          : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidationException
1569
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
1570
 
1571
New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "userName" is not valid. Change the value of the "userName" argument and run the operation again."
1572
At C:\projects\azurepsdrive\tests\test.psm1:98 char:13
1573
+     $cred = New-Object System.Management.Automation.PSCredential($azu ...
1574
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1575
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
1576
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
1577
 
1578
Connect-AzureRmAccount : Cannot bind argument to parameter 'Credential' because it is null.
1579
At C:\projects\azurepsdrive\tests\test.psm1:100 char:72
1580
+ ... file\Login-AzureRmAccount -ServicePrincipal -Credential $cred -Tenant ...
1581
+                                                             ~~~~~
1582
    + CategoryInfo          : InvalidData: (:) [Connect-AzureRmAccount], ParameterBindingValidationException
1583
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
1584
 
1585
Install SHiPS module from PowerShellGallery - required dependency for AzurePSDrive
1586
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
1587
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.

Why the Az.* module dependencies?

I just installed the AzurePSDrive module, and it pulled down a bunch of Az.* modules that it is dependent on: Az.Compute, Az.Profile, Az.Resources, Az.Storage. These are installed, even though I already have AzureRM.Compute, AzureRM.Profile, AzureRM.Resources, and AzureRM.Storage already installed. There is obviously some redundancy going on here. Can someone please explain why these extra modules are necessary? Is this simply to ensure that you have the right DLLs downloaded and loaded in memory so that you can reference Azure types internally in the AzurePSDrive module?

Is it possible to change subscription/tenant?

I love this project and its possibilities.

I have one issue so far, on my Azure credentials I have access to multiple subscription. Is there a way to change subscription either before or after you created the PSDrive?

/Jens

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.