Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.21k stars 3.81k forks source link

Import-AzureRmAutomationDscConfiguration: Needs to check for existence of file before making API calls #1804

Open pcgeek86 opened 8 years ago

pcgeek86 commented 8 years ago

Issue

The Import-AzureRmAutomationDscConfiguration command doesn't check for the existence of the file path specified in the -SourcePath parameter. If the file doesn't exist, the command still attempts to make the API call to Microsoft Azure, which returns the exception below.

Import-AzureRmAutomationDscConfiguration : BadRequest: {"Message":"Invalid argument specified. Argument script cannot be null."}
At C:\Users\TrevorSullivan\Documents\Import DSC Configuration.ps1:26 char:1
+ Import-AzureRmAutomationDscConfiguration @DscConfiguration;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Import-AzureRmAutomationDscConfiguration], CloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.ImportAzureAutomationDscConfiguration

Expected Result

The Import-AzureRmAutomationDscConfiguration command should check for the existence of the file in -SourcePath before it attempts to make any API calls against Azure. If the file does not exist, a more useful error message should be thrown, instead of the generic one coming back from the ARM REST API.

Cheers, Trevor Sullivan Microsoft MVP: PowerShell http://trevorsullivan.net http://twitter.com/pcgeek86

markcowl commented 8 years ago

@pcgeek86 Simple parameter validation. Adding in the automation team for a fix.

peterschen commented 8 years ago

Additionally the current directory should be respected. When I execute the command in D:\mydscstuff and use .\mysuperconfiguration.ps1 I'll receive the same message as Trevor although the file does exist. Using (Get-Item .\mysuperconfiguration.ps1).FullName does the trick.

maddieclayton commented 6 years ago

@vrdmr Can you take a look at this feature request?