diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c7d4626..ce17aa16b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-Icon` and `-Color` parameters to `Set-PnPList` cmdlet. [#4409](https://github.com/pnp/powershell/pull/4409) - Added `Remove-PnPTenantRestrictedSearchAllowedList` cmdlet to removes site URLs from the allowed list when Restricted SharePoint Search is enabled. [#4399](https://github.com/pnp/powershell/pull/4399) - Added `Get-PnPDeletedFlow` cmdlet to retrieve a list of flows which are soft deleted. [#4396](https://github.com/pnp/powershell/pull/4396) +- Added `Restore-PnPFlow` cmdlet which allows for undeleting a flow within 21 days of deletion. [#4415](https://github.com/pnp/powershell/pull/4415) - Added `-ExcludeDeprecated` to `Export-PnpTaxonomy` which allows for deprecated terms to be excluded from the export [#4053](https://github.com/pnp/powershell/pull/4053) ### Changed @@ -44,6 +45,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - `Remove-PnPContentType` and `Remove-PnPContentTypeFromList` now use PnP Core SDK for processing requests. [#4390](https://github.com/pnp/powershell/pull/4390) - `Clear-PnPRecycleBinItem` , `Move-PnPRecycleBinItem` and `Restore-PnPRecycleBinItem` cmdlets now use PnP Core SDK for processing requests. [#4393](https://github.com/pnp/powershell/pull/4393/) - `Get-PnPSearchCrawlLog` cmdlet now shows a warning in case application permissions are used. [#4391](https://github.com/pnp/powershell/pull/4391) +- All Power Platform cmdlets no longer require an environment to be specified. If omitted, the default environment will be retrieved and used. [#4415](https://github.com/pnp/powershell/pull/4415) ### Fixed diff --git a/documentation/Add-PnPFlowOwner.md b/documentation/Add-PnPFlowOwner.md index 1630df83e..6908ffcd3 100644 --- a/documentation/Add-PnPFlowOwner.md +++ b/documentation/Add-PnPFlowOwner.md @@ -20,7 +20,7 @@ Assigns/updates permissions to a Power Automate flow ## SYNTAX ```powershell -Add-PnPFlowOwner -Environment -Identity -User -Role [-AsAdmin] [-Verbose] +Add-PnPFlowOwner [-Environment ] -Identity -User -Role [-AsAdmin] [-Verbose] ``` ## DESCRIPTION @@ -30,42 +30,42 @@ This cmdlet assigns/updates permissions for a user to a Power Automate flow. ### Example 1 ```powershell -Add-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -Role CanEdit +Add-PnPFlowOwner -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -Role CanEdit ``` -Assigns the specified user with 'CanEdit' access level to the specified flow +Assigns the specified user with 'CanEdit' access level to the specified flow in the default environment ### Example 2 ```powershell -Add-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User 6844c04a-8ee7-40ad-af66-28f6e948cd04 -Role CanView +Add-PnPFlowOwner -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User 6844c04a-8ee7-40ad-af66-28f6e948cd04 -Role CanView ``` -Assigns the specified user with 'CanView' access level to the specified flow +Assigns the specified user with 'CanView' access level to the specified flow in the default environment ### Example 3 ```powershell -Add-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User 6844c04a-8ee7-40ad-af66-28f6e948cd04 -Role CanViewWithShare +Add-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User 6844c04a-8ee7-40ad-af66-28f6e948cd04 -Role CanViewWithShare ``` -Assigns the specified user with 'CanViewWithShare' access level to the specified flow +Assigns the specified user with 'CanViewWithShare' access level to the specified flow in the specified environment ### Example 4 ```powershell -Add-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -AsAdmin -Role CanEdit +Add-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -AsAdmin -Role CanEdit ``` -Assigns the specified user with 'CanEdit' access level to the specified flow as admin +Assigns the specified user with 'CanEdit' access level to the specified flow as admin in the specified environment ## PARAMETERS ### -Environment -The Power Platform environment that hosts the Power Automate Flow to add the permissions to. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Disable-PnPFlow.md b/documentation/Disable-PnPFlow.md index 4e13e7130..364f94848 100644 --- a/documentation/Disable-PnPFlow.md +++ b/documentation/Disable-PnPFlow.md @@ -20,7 +20,7 @@ Disables a specific flow ## SYNTAX ```powershell -Disable-PnPFlow -Environment -Identity [-AsAdmin] [-Connection ] +Disable-PnPFlow [-Environment ] -Identity [-AsAdmin] [-Connection ] ``` ## DESCRIPTION @@ -30,11 +30,17 @@ This cmdlet disables a specific flow ### Example 1 ```powershell -$environment = Get-PnPFlowEnvironment -Disable-PnPFlow -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +Disable-PnPFlow -Identity fba63225-baf9-4d76-86a1-1b42c917a182 ``` -Disables the specified flow. +Disables the specified flow in the default environment + +### Example 2 +```powershell +Disable-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +``` + +Disables the specified flow in the specified environment ## PARAMETERS @@ -70,17 +76,17 @@ Accept wildcard characters: False ``` ### -Environment -The name of the environment or an Environment object to retrieve the available flows for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Enable-PnPFlow.md b/documentation/Enable-PnPFlow.md index 0969c2a55..90340b878 100644 --- a/documentation/Enable-PnPFlow.md +++ b/documentation/Enable-PnPFlow.md @@ -20,7 +20,7 @@ Enables a specific flow ## SYNTAX ```powershell -Enable-PnPFlow -Environment -Identity [-AsAdmin] +Enable-PnPFlow [-Environment ] -Identity [-AsAdmin] [-Connection ] ``` @@ -31,26 +31,32 @@ This cmdlet enables a specific flow ### Example 1 ```powershell -$environment = Get-PnPFlowEnvironment -Enable-PnPFlow -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +Enable-PnPFlow -Identity fba63225-baf9-4d76-86a1-1b42c917a182 ``` -Enables the specified flow +Enables the specified flow in the default environment + +### Example 2 +```powershell +Enable-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +``` + +Enables the specified flow in the specified environment ## PARAMETERS ### -Environment -The name of the environment or an Environment object to retrieve the available flows for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Export-PnPFlow.md b/documentation/Export-PnPFlow.md index 224fd4a0f..a3b2e2c25 100644 --- a/documentation/Export-PnPFlow.md +++ b/documentation/Export-PnPFlow.md @@ -21,7 +21,7 @@ Exports a Microsoft Power Automate Flow ### As ZIP Package ```powershell -Export-PnPFlow -Environment -Identity +Export-PnPFlow [-Environment ] -Identity [-AsZipPackage] [-PackageDisplayName ] [-PackageDescription ] [-PackageCreatedBy ] [-PackageSourceEnvironment ] [-OutPath ] [-Force] [-Connection ] @@ -29,7 +29,7 @@ Export-PnPFlow -Environment -Identity -Identity +Export-PnPFlow [-Environment ] -Identity [-Connection ] ``` @@ -42,14 +42,20 @@ Many times exporting a Microsoft Power Automate Flow will not be possible due to ### Example 1 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -IsDefault $true -Export-PnPFlow -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +Export-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 ``` -This will export the specified Microsoft Power Automate Flow from the default Power Platform environment as an output to the current output of PowerShell +This will export the specified Microsoft Power Automate Flow from the specified Power Platform environment as an output to the current output of PowerShell ### Example 2 ```powershell +Export-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +``` + +This will export the specified Microsoft Power Automate Flow from the default Power Platform environment as an output to the current output of PowerShell + +### Example 3 +```powershell Get-PnPPowerPlatformEnvironment | foreach { Get-PnPFlow -Environment $_.Name } | foreach { Export-PnPFlow -Environment $_.Properties.EnvironmentDetails.Name -Identity $_ -OutPath "c:\flows\$($_.Name).zip" -AsZipPackage } ``` @@ -89,17 +95,17 @@ Accept wildcard characters: False ``` ### -Environment -The environment which contains the flow. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Export-PnPPowerApp.md b/documentation/Export-PnPPowerApp.md index 3a6d66996..8e1c0f1f9 100644 --- a/documentation/Export-PnPPowerApp.md +++ b/documentation/Export-PnPPowerApp.md @@ -20,7 +20,7 @@ Exports a Microsoft Power App ## SYNTAX ``` -Export-PnPPowerApp -Environment -Identity +Export-PnPPowerApp [-Environment ] -Identity [-PackageDisplayName ] [-PackageDescription ] [-PackageCreatedBy ] [-PackageSourceEnvironment ] [-OutPath ] [-Force] [-Connection ] [] @@ -35,18 +35,16 @@ Many times exporting a Microsoft Power App will not be possible due to various r ### Example 1 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -IsDefault $true -Export-PnPPowerApp -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -OutPath "C:\Users\user1\Downloads\test_20230408152624.zip" +Export-PnPPowerApp -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -OutPath "C:\Users\user1\Downloads\test_20230408152624.zip" ``` This will export the specified Microsoft Power App from the default Power Platform environment as an output to the path specified in the command as -OutPath ### Example 2 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -IsDefault $true -Export-PnPPowerApp -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -OutPath "C:\Users\user1\Downloads\test_20230408152624.zip" -PackageDisplayName "MyAppDisplayName" -PackageDescription "Package exported using PnP Powershell" -PackageCreatedBy "Siddharth Vaghasia" -PackageSourceEnvironment "UAT Environment" +Export-PnPPowerApp -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -OutPath "C:\Users\user1\Downloads\test_20230408152624.zip" -PackageDisplayName "MyAppDisplayName" -PackageDescription "Package exported using PnP Powershell" -PackageCreatedBy "Siddharth Vaghasia" -PackageSourceEnvironment "UAT Environment" ``` -This will export the specified Microsoft Power App from the default Power Platform environment with metadata specified +This will export the specified Microsoft Power App from the specified Power Platform environment with metadata specified ### Example 3 ```powershell @@ -74,17 +72,17 @@ Accept wildcard characters: False ``` ### -Environment -The environment which contains the App. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Get-PnPDeletedFlow.md b/documentation/Get-PnPDeletedFlow.md index 644873a09..4f93027bc 100644 --- a/documentation/Get-PnPDeletedFlow.md +++ b/documentation/Get-PnPDeletedFlow.md @@ -56,21 +56,20 @@ Returns all the deleted flows for a given Power Platform environment belonging ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the available flows for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: Required: False Position: Named Default value: The default environment -Accept pipeline input: False +Accept pipeline input: True Accept wildcard characters: False ``` - ### -Connection Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. diff --git a/documentation/Get-PnPFlow.md b/documentation/Get-PnPFlow.md index 2328b0a9c..8f1fa5532 100644 --- a/documentation/Get-PnPFlow.md +++ b/documentation/Get-PnPFlow.md @@ -61,17 +61,17 @@ Returns a specific flow from the default Power Platform environment ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the available flows for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: Required: False Position: Named Default value: The default environment -Accept pipeline input: False +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Get-PnPFlowOwner.md b/documentation/Get-PnPFlowOwner.md index a92a19d9f..d87df756e 100644 --- a/documentation/Get-PnPFlowOwner.md +++ b/documentation/Get-PnPFlowOwner.md @@ -20,7 +20,7 @@ Returns the owners of a Power Automate flow ## SYNTAX ```powershell -Get-PnPFlowOwner -Environment -Identity [-AsAdmin] +Get-PnPFlowOwner [-Environment ] -Identity [-AsAdmin] ``` ## DESCRIPTION @@ -30,24 +30,30 @@ This cmdlet returns the Power Automate flow owners for a given Power Automate Fl ### Example 1 ```powershell -Get-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity 33f78dac-7e93-45de-ab85-67cad0f6ee30 +Get-PnPFlowOwner -Identity 33f78dac-7e93-45de-ab85-67cad0f6ee30 ``` Returns all the owners of the Power Automate Flow with the provided identifier on the default Power Platform environment +### Example 2 +```powershell +Get-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity 33f78dac-7e93-45de-ab85-67cad0f6ee30 +``` +Returns all the owners of the Power Automate Flow with the provided identifier on the specified Power Platform environment + ## PARAMETERS ### -Environment -The Power Platform environment that hosts the Power Automate Flow to retrieve the owners of. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Get-PnPFlowRun.md b/documentation/Get-PnPFlowRun.md index 1a54c17eb..eda9535e4 100644 --- a/documentation/Get-PnPFlowRun.md +++ b/documentation/Get-PnPFlowRun.md @@ -20,7 +20,7 @@ Returns the flows runs for a given flow. ## SYNTAX ```powershell -Get-PnPFlowRun -Environment -Flow [-Identity ] +Get-PnPFlowRun [-Environment ] -Flow [-Identity ] [-Connection ] ``` @@ -31,26 +31,23 @@ This cmdlet returns the flow runs for a given flow. ### Example 1 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Get-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 +Get-PnPFlowRun -Flow fba63225-baf9-4d76-86a1-1b42c917a182 ``` -This returns all the flow runs for a given flow +This returns all the flow runs for a given flow in the default environment ### Example 2 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Get-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 +Get-PnPFlowRun -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 ``` -This returns a specific flow run +This returns a specific flow run for a given flow in a specific environment ### Example 3 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -$flowrun = Get-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 +$flowrun = Get-PnPFlowRun -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 $flowrun.Properties.trigger ``` -This returns a specific flow run trigger information as below +This returns the trigger information of a run of a specific flow located in the default environment as shown below ### Output ```powershell @@ -63,14 +60,12 @@ Code : OK Status : Succeeded ``` - ### Example 4 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -$flowruns = Get-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 +$flowruns = Get-PnPFlowRun -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Flow fba63225-baf9-4d76-86a1-1b42c917a182 $flowruns.Properties.trigger ``` -This returns a specific flows trigger information as below +This returns the trigger information of a run of a specific flow located in the specified environment as shown below ### Output ```powershell @@ -99,21 +94,20 @@ Code : OK Status : Succeeded ``` - ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the available flows for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Get-PnPPowerApp.md b/documentation/Get-PnPPowerApp.md index 75b3fc1f5..3d12c5b9b 100644 --- a/documentation/Get-PnPPowerApp.md +++ b/documentation/Get-PnPPowerApp.md @@ -31,22 +31,20 @@ This cmdlet returns the Power Apps for a given enviroment. ### Example 1 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Get-PnPPowerApp -Environment $environment +Get-PnPPowerApp ``` -This returns all the apps for a given Power Platform environment +This returns all the apps for the default environment ### Example 2 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Get-PnPPowerApp -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +Get-PnPPowerApp -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 ``` -This returns a specific app +This returns a specific app from a specific environment ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the available Power Apps for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml Type: PowerPlatformEnvironmentPipeBind diff --git a/documentation/Get-PnPPowerPlatformCustomConnector.md b/documentation/Get-PnPPowerPlatformCustomConnector.md index 07044c54b..51d4d1689 100644 --- a/documentation/Get-PnPPowerPlatformCustomConnector.md +++ b/documentation/Get-PnPPowerPlatformCustomConnector.md @@ -30,20 +30,20 @@ This cmdlet returns the custom connectors on a given enviroment. ### Example 1 ```powershell -Get-PnPPowerPlatformCustomConnector -Environment (Get-PnPPowerPlatformEnvironment) +Get-PnPPowerPlatformCustomConnector -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") ``` This returns all the custom connectors for a given Power Platform environment ### Example 2 ```powershell -Get-PowerPlatformConnectorPipeBind -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +Get-PowerPlatformConnectorPipeBind -Identity fba63225-baf9-4d76-86a1-1b42c917a182 ``` This returns a specific custom connector on the default Power Platform environment ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment instance to retrieve the available custom connectors for. If omitted, the default environment will be used. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml Type: PowerPlatformEnvironmentPipeBind diff --git a/documentation/Get-PnPPowerPlatformSolution.md b/documentation/Get-PnPPowerPlatformSolution.md index 5a8c3c729..30d7feb0a 100644 --- a/documentation/Get-PnPPowerPlatformSolution.md +++ b/documentation/Get-PnPPowerPlatformSolution.md @@ -30,20 +30,20 @@ This cmdlet returns the PowerPlatform solution on a given enviroment. ### Example 1 ```powershell -Get-PnPPowerPlatformSolution -Environment (Get-PnPPowerPlatformEnvironment) +Get-PnPPowerPlatformSolution -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") ``` This returns all the solutions for a given Power Platform environment ### Example 2 ```powershell -Get-PnPPowerPlatformSolution -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Name 'My Solution Name' +Get-PnPPowerPlatformSolution -Name 'My Solution Name' ``` This returns a specific solution on the default Power Platform environment ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment instance to retrieve the available solutions for. If omitted, the default environment will be used. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml Type: PowerPlatformEnvironmentPipeBind diff --git a/documentation/Remove-PnPFlow.md b/documentation/Remove-PnPFlow.md index c0c3278eb..41acc6cae 100644 --- a/documentation/Remove-PnPFlow.md +++ b/documentation/Remove-PnPFlow.md @@ -19,7 +19,7 @@ Removes the specified flow. ## SYNTAX ```powershell -Remove-PnPFlow -Environment -Identity [-AsAdmin] +Remove-PnPFlow [-Environment ] -Identity [-AsAdmin] [-Force] [-ThrowExceptionIfPowerAutomateNotFound] [-Connection ] ``` @@ -30,19 +30,17 @@ This cmdlet removes the specified flow. ### Example 1 ```powershell -$environment = Get-PnPFlowEnvironment -Remove-PnPFlow -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +Remove-PnPFlow -Identity fba63225-baf9-4d76-86a1-1b42c917a182 ``` -This removes the specified flow. +This removes the specified flow from the default environment. -### Example 1 +### Example 2 ```powershell -$environment = Get-PnPFlowEnvironment -Remove-PnPFlow -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -ThrowExceptionIfPowerAutomateNotFound +Remove-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -ThrowExceptionIfPowerAutomateNotFound ``` -This removes the specified flow and throws an exception if the specified flow is not present. +This removes the specified flow located in the specified environment and throws an exception if the specified flow is not present. ## PARAMETERS @@ -78,17 +76,17 @@ Accept wildcard characters: False ``` ### -Environment -The name of the environment which contains the flow. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Remove-PnPFlowOwner.md b/documentation/Remove-PnPFlowOwner.md index 5e86f32ef..1f73d039f 100644 --- a/documentation/Remove-PnPFlowOwner.md +++ b/documentation/Remove-PnPFlowOwner.md @@ -21,7 +21,7 @@ Removes owner permissions to a Power Automate flow ## SYNTAX ```powershell -Remove-PnPFlowOwner -Environment -Identity -User [-AsAdmin] [-Force] [-Verbose] +Remove-PnPFlowOwner [-Environment ] -Identity -User [-AsAdmin] [-Force] [-Verbose] ``` ## DESCRIPTION @@ -31,42 +31,42 @@ This cmdlet removes owner permissions for a user from a Power Automate flow. ### Example 1 ```powershell -Remove-PnPFlowOwner (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com +Remove-PnPFlowOwner -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com ``` -Removes the specified user from the specified Power Automate flow +Removes the specified user from the specified Power Automate flow located in the default environment ### Example 2 ```powershell -Remove-PnPFlowOwner (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User 6844c04a-8ee7-40ad-af66-28f6e948cd04 +Remove-PnPFlowOwner -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User 6844c04a-8ee7-40ad-af66-28f6e948cd04 ``` -Removes the specified user from the specified Power Automate flow +Removes the specified user from the specified Power Automate flow located in the default environment ### Example 3 ```powershell -Remove-PnPFlowOwner (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -AsAdmin +Remove-PnPFlowOwner (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -AsAdmin ``` -Removes the specified user from the specified Power Automate flow as an admin +Removes the specified user from the specified Power Automate flow as an admin in the specified environment ### Example 4 ```powershell -Remove-PnPFlowOwner (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -AsAdmin -Force +Remove-PnPFlowOwner (Get-PnPPowerPlatformEnvironment -Identity "myenvironment) -Identity f07c34a9-a586-4e58-91fb-e7ea19741b61 -User username@tenant.onmicrosoft.com -AsAdmin -Force ``` -Removes the specified user from the specified Power Automate Flow as admin, without asking for confirmation +Removes the specified user from the specified Power Automate Flow as admin, without asking for confirmation, in the specified environment ## PARAMETERS ### -Environment -The Power Platform environment that hosts the Power Automate Flow to remove the permissions from. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Restart-PnPFlowRun.md b/documentation/Restart-PnPFlowRun.md index 6c1e4c1b6..fd3a5f729 100644 --- a/documentation/Restart-PnPFlowRun.md +++ b/documentation/Restart-PnPFlowRun.md @@ -19,7 +19,7 @@ Restarts/resubmits a specific flow run for the specified Microsoft Power Automat ## SYNTAX ```powershell -Restart-PnPFlowRun -Environment -Flow -Identity [-Force] +Restart-PnPFlowRun [-Environment ] -Flow -Identity [-Force] ``` ## DESCRIPTION @@ -29,33 +29,32 @@ This cmdlet restarts/resubmits a specific Power Automate flow run. ### Example 1 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Restart-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 +Restart-PnPFlowRun -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 ``` -This restarts the specified flow run of the specified flow +This restarts the specified flow run of the specified flow located in the default environment ### Example 2 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Restart-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 -Force +$environment = +Restart-PnPFlowRun -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 -Force ``` -This restarts the specified flow run of the specified flow without confirmation +This restarts the specified flow run of the specified flow without confirmation located in the specified environment ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the available flows for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/documentation/Restore-PnPFlow.md b/documentation/Restore-PnPFlow.md new file mode 100644 index 000000000..e1a2f298a --- /dev/null +++ b/documentation/Restore-PnPFlow.md @@ -0,0 +1,98 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Restore-PnPFlow.html +external help file: PnP.PowerShell.dll-Help.xml +title: Restore-PnPFlow +--- + +# Restore-PnPFlow + +## SYNOPSIS + +**Required Permissions** + +* Azure: management.azure.com + +Restores a specific flow + +## SYNTAX + +```powershell +Restore-PnPFlow [-Environment ] -Identity [-Connection ] +``` + +## DESCRIPTION +This cmdlet Restores a specific flow + +## EXAMPLES + +### Example 1 +```powershell +Restore-PnPFlow -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +``` + +Restores the specified flow located in the default environment. + +### Example 2 +```powershell +Restore-PnPFlow -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 +``` + +Restores the specified flow located in the specified environment + +## PARAMETERS + +### -Connection +Optional connection to be used by the cmdlet. +Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. + +```yaml +Type: PnPConnection +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Environment +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. + +```yaml +Type: PowerPlatformEnvironmentPipeBind +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: The default environment +Accept pipeline input: True +Accept wildcard characters: False +``` + +### -Identity +Identity of the flow to Restore. + +```yaml +Type: PowerAutomateFlowPipeBind +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) + + diff --git a/documentation/Set-PnPPowerAppByPassConsent.md b/documentation/Set-PnPPowerAppByPassConsent.md index 1e3e57f81..be34ee427 100644 --- a/documentation/Set-PnPPowerAppByPassConsent.md +++ b/documentation/Set-PnPPowerAppByPassConsent.md @@ -32,21 +32,20 @@ This command can be used to set the bypassConsent flag of an PowerApps to true o ### Example 1 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Set-PnPPowerAppByPassConsent -Environment $environment -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -ByPassConsent true +Set-PnPPowerAppByPassConsent -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -ByPassConsent true ``` -This sets the bypassConsent flag on the specified Power App to true +This sets the bypassConsent flag on the specified Power App in the provided environment to true ### Example 2 ```powershell Set-PnPPowerAppByPassConsent -Identity fba63225-baf9-4d76-86a1-1b42c917a182 -ByPassConsent false ``` -This sets the bypassConsent flag on the specified Power App to flag on the default environment +This sets the bypassConsent flag on the specified Power App in the default environment ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the available Power Apps for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml Type: PowerPlatformEnvironmentPipeBind diff --git a/documentation/Stop-PnPFlowRun.md b/documentation/Stop-PnPFlowRun.md index b72ba6d50..0d4027604 100644 --- a/documentation/Stop-PnPFlowRun.md +++ b/documentation/Stop-PnPFlowRun.md @@ -19,7 +19,7 @@ Stops/cancels a specific run of a Microsoft flow. ## SYNTAX ```powershell -Stop-PnPFlowRun -Environment -Flow -Identity [-Force] [-Connection ] +Stop-PnPFlowRun [-Environment ] -Flow -Identity [-Force] [-Connection ] ``` ## DESCRIPTION @@ -29,18 +29,16 @@ This cmdlet cancels a running Power Automate flow run. ### Example 1 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Stop-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 +Stop-PnPFlowRun -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 ``` -This cancels the specified flow run of the specified flow. +This cancels the specified flow run of the specified flow located in the default environment. ### Example 2 ```powershell -$environment = Get-PnPPowerPlatformEnvironment -Stop-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 -Force +Stop-PnPFlowRun -Environment (Get-PnPPowerPlatformEnvironment -Identity "myenvironment") -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 -Force ``` -This cancels the specified flow run of the specified flow without confirmation. +This cancels the specified flow run located in the specified environment of the specified flow without confirmation. ## PARAMETERS @@ -59,17 +57,17 @@ Accept wildcard characters: False ``` ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the available flows for. +The name of the Power Platform environment or an Environment instance. If omitted, the default environment will be used. ```yaml -Type: PowerAutomateEnvironmentPipeBind +Type: PowerPlatformEnvironmentPipeBind Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named -Default value: None -Accept pipeline input: False +Default value: The default environment +Accept pipeline input: True Accept wildcard characters: False ``` diff --git a/src/Commands/PowerPlatform/Environment/GetPowerPlatformCustomConnector.cs b/src/Commands/PowerPlatform/Environment/GetPowerPlatformCustomConnector.cs index 84b96dd44..9f57c11d2 100644 --- a/src/Commands/PowerPlatform/Environment/GetPowerPlatformCustomConnector.cs +++ b/src/Commands/PowerPlatform/Environment/GetPowerPlatformCustomConnector.cs @@ -1,11 +1,8 @@ using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Utilities.REST; -using System; using System.Management.Automation; -using System.Linq; using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Utilities; -using PnP.PowerShell.Commands.Attributes; namespace PnP.PowerShell.Commands.PowerPlatform.Environment { @@ -23,26 +20,8 @@ public class GetPowerPlatformCustomConnector : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - string environmentName = null; - string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - string powerAppsUrl = PowerPlatformUtility.GetPowerAppsEndpoint(Connection.AzureEnvironment); - if (ParameterSpecified(nameof(Environment))) - { - environmentName = Environment.GetName(); - WriteVerbose($"Using environment as provided '{environmentName}'"); - } - else - { - var environments = GraphHelper.GetResultCollection(this, Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken); - environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; - - if (string.IsNullOrEmpty(environmentName)) - { - throw new Exception($"No default environment found, please pass in a specific environment name using the {nameof(Environment)} parameter"); - } - - WriteVerbose($"Using default environment as retrieved '{environmentName}'"); - } + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; + var powerAppsUrl = PowerPlatformUtility.GetPowerAppsEndpoint(Connection.AzureEnvironment); if (ParameterSpecified(nameof(Identity))) { diff --git a/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs b/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs index be501c4f3..07f692739 100644 --- a/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs +++ b/src/Commands/PowerPlatform/Environment/GetPowerPlatformEnvironment.cs @@ -1,5 +1,4 @@ -using PnP.PowerShell.Commands.Attributes; -using PnP.PowerShell.Commands.Base; +using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Utilities.REST; using System.Management.Automation; using System.Linq; diff --git a/src/Commands/PowerPlatform/Environment/GetPowerPlatformSolution.cs b/src/Commands/PowerPlatform/Environment/GetPowerPlatformSolution.cs index eee07fc84..222f5b7d0 100644 --- a/src/Commands/PowerPlatform/Environment/GetPowerPlatformSolution.cs +++ b/src/Commands/PowerPlatform/Environment/GetPowerPlatformSolution.cs @@ -21,19 +21,17 @@ public class GetPowerPlatformSolution: PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - string environmentName = null; + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; string dynamicsScopeUrl = null; string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); var environments = GraphHelper.GetResultCollection(this, Connection, $"{baseUrl}/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken); if (ParameterSpecified(nameof(Environment))) { - environmentName = Environment.GetName().ToLower(); WriteVerbose($"Using environment as provided '{environmentName}'"); dynamicsScopeUrl = environments.FirstOrDefault(e => e.Properties.DisplayName.ToLower() == environmentName || e.Name.ToLower() == environmentName)?.Properties.LinkedEnvironmentMetadata.InstanceApiUrl; } else { - environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; dynamicsScopeUrl = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Properties.LinkedEnvironmentMetadata.InstanceApiUrl; if (string.IsNullOrEmpty(environmentName)) { diff --git a/src/Commands/PowerPlatform/PowerApps/ExportPowerApp.cs b/src/Commands/PowerPlatform/PowerApps/ExportPowerApp.cs index 6bf246cab..91fcced63 100644 --- a/src/Commands/PowerPlatform/PowerApps/ExportPowerApp.cs +++ b/src/Commands/PowerPlatform/PowerApps/ExportPowerApp.cs @@ -1,15 +1,8 @@ using PnP.PowerShell.Commands.Attributes; using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Base.PipeBinds; -using PnP.PowerShell.Commands.Utilities.REST; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Management.Automation; -using System.Net.Http; -using System.Text.Json; -using System.Threading; using PnP.PowerShell.Commands.Utilities; namespace PnP.PowerShell.Commands.PowerPlatform.PowerApps @@ -18,9 +11,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerApps [RequiredApiApplicationPermissions("https://management.azure.com/.default")] public class ExportPowerApp : PnPAzureManagementApiCmdlet { - - [Parameter(Mandatory = true)] - + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -66,7 +57,7 @@ protected override void ExecuteCmdlet() } } - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; var appName = Identity.GetName(); var wrapper = PowerAppsUtility.GetWrapper(Connection.HttpClient, environmentName, AccessToken, appName, Connection.AzureEnvironment); diff --git a/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs b/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs index c0a5c0085..3aa608af7 100644 --- a/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs +++ b/src/Commands/PowerPlatform/PowerApps/GetPowerApp.cs @@ -3,8 +3,6 @@ using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Utilities; using PnP.PowerShell.Commands.Utilities.REST; -using System; -using System.Linq; using System.Management.Automation; namespace PnP.PowerShell.Commands.PowerPlatform.PowerApps @@ -25,27 +23,8 @@ public class GetPowerApp : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - string environmentName = null; - string powerAppsUrl = PowerPlatformUtility.GetPowerAppsEndpoint(Connection.AzureEnvironment); - if (ParameterSpecified(nameof(Environment))) - { - environmentName = Environment.GetName(); - - WriteVerbose($"Using environment as provided '{environmentName}'"); - } - else - { - string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - var environments = GraphHelper.GetResultCollection(this, Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken); - environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; - - if(string.IsNullOrEmpty(environmentName)) - { - throw new Exception($"No default environment found, please pass in a specific environment name using the {nameof(Environment)} parameter"); - } - - WriteVerbose($"Using default environment as retrieved '{environmentName}'"); - } + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; + var powerAppsUrl = PowerPlatformUtility.GetPowerAppsEndpoint(Connection.AzureEnvironment); if (ParameterSpecified(nameof(Identity))) { diff --git a/src/Commands/PowerPlatform/PowerApps/SetPowerAppByPassConsent.cs b/src/Commands/PowerPlatform/PowerApps/SetPowerAppByPassConsent.cs index 159e3589a..b380703d7 100644 --- a/src/Commands/PowerPlatform/PowerApps/SetPowerAppByPassConsent.cs +++ b/src/Commands/PowerPlatform/PowerApps/SetPowerAppByPassConsent.cs @@ -2,8 +2,6 @@ using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Utilities.REST; -using System; -using System.Linq; using System.Management.Automation; using PnP.PowerShell.Commands.Utilities; @@ -24,28 +22,8 @@ public class PnPPowerAppByPassConsent : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - string environmentName = null; - string powerAppsUrl = PowerPlatformUtility.GetPowerAppsEndpoint(Connection.AzureEnvironment); - if (ParameterSpecified(nameof(Environment))) - { - environmentName = Environment.GetName(); - - WriteVerbose($"Using environment as provided '{environmentName}'"); - } - else - { - string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - var environments = GraphHelper.GetResultCollection(this, Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken); - environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; - - if (string.IsNullOrEmpty(environmentName)) - { - throw new Exception($"No default environment found, please pass in a specific environment name using the {nameof(Environment)} parameter"); - } - - WriteVerbose($"Using default environment as retrieved '{environmentName}'"); - } - + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; + var powerAppsUrl = PowerPlatformUtility.GetPowerAppsEndpoint(Connection.AzureEnvironment); var appName = Identity.GetName(); WriteVerbose($"Setting specific PowerApp with the provided name '{appName}' consent within the environment '{environmentName}'"); diff --git a/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs index 648d9b382..1eecde99f 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/AddFlowOwner.cs @@ -10,7 +10,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsCommon.Add, "PnPFlowOwner")] public class AddFlowOwner : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -27,7 +27,7 @@ public class AddFlowOwner : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; if (string.IsNullOrEmpty(environmentName)) { throw new PSArgumentException("Environment not found.", nameof(Environment)); diff --git a/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs index aec590f24..65f6b15c8 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/DisableFlow.cs @@ -9,7 +9,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsLifecycle.Disable, "PnPFlow")] public class DisableFlow : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -20,7 +20,7 @@ public class DisableFlow : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; var flowName = Identity.GetName(); string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); RestHelper.Post(Connection.HttpClient, $"{baseUrl}/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/stop?api-version=2016-11-01", AccessToken); diff --git a/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs index da8cf2300..4746b75a3 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/EnableFlow.cs @@ -9,7 +9,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsLifecycle.Enable, "PnPFlow")] public class EnableFlow : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -20,7 +20,7 @@ public class EnableFlow : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; var flowName = Identity.GetName(); string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); RestHelper.Post(Connection.HttpClient, $"{baseUrl}/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/start?api-version=2016-11-01", AccessToken); diff --git a/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs index 73a08cdfd..22fff8d63 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs @@ -15,8 +15,8 @@ public class ExportFlow : PnPAzureManagementApiCmdlet private const string ParameterSet_ASJSON = "As Json"; private const string ParameterSet_ASPACKAGE = "As ZIP Package"; - [Parameter(Mandatory = true, ParameterSetName = ParameterSet_ASPACKAGE)] - [Parameter(Mandatory = true, ParameterSetName = ParameterSet_ASJSON)] + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_ASPACKAGE)] + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_ASJSON)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true, ParameterSetName = ParameterSet_ASPACKAGE)] @@ -66,7 +66,7 @@ protected override void ExecuteCmdlet() } } - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; var flowName = Identity.GetName(); if (AsZipPackage) diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetDeletedFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/GetDeletedFlow.cs index 5b33ea6e9..ee5864129 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetDeletedFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetDeletedFlow.cs @@ -1,12 +1,9 @@ using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Utilities.REST; -using System; using System.Linq; using System.Management.Automation; -using PnP.PowerShell.Commands.Enums; using PnP.PowerShell.Commands.Utilities; -using PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate; namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate { @@ -20,27 +17,8 @@ public class GetDeletedFlow : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - string environmentName = null; - string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - if (ParameterSpecified(nameof(Environment))) - { - environmentName = Environment.GetName(); - - WriteVerbose($"Using environment as provided '{environmentName}'"); - } - else - { - var environments = GraphHelper.GetResultCollection(this, Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken); - environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; - - if(string.IsNullOrEmpty(environmentName)) - { - throw new Exception($"No default environment found, please pass in a specific environment name using the {nameof(Environment)} parameter"); - } - - WriteVerbose($"Using default environment as retrieved '{environmentName}'"); - } - + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; + var baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); WriteVerbose($"Retrieving all Power Automate Flows within environment '{environmentName}'"); diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs index 9e53b76f0..d64ab73a3 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs @@ -1,8 +1,6 @@ using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Utilities.REST; -using System; -using System.Linq; using System.Management.Automation; using PnP.PowerShell.Commands.Enums; using PnP.PowerShell.Commands.Utilities; @@ -31,26 +29,8 @@ public class GetFlow : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - string environmentName = null; + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - if (ParameterSpecified(nameof(Environment))) - { - environmentName = Environment.GetName(); - - WriteVerbose($"Using environment as provided '{environmentName}'"); - } - else - { - var environments = GraphHelper.GetResultCollection(this, Connection, baseUrl + "/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", AccessToken); - environmentName = environments.FirstOrDefault(e => e.Properties.IsDefault.HasValue && e.Properties.IsDefault == true)?.Name; - - if(string.IsNullOrEmpty(environmentName)) - { - throw new Exception($"No default environment found, please pass in a specific environment name using the {nameof(Environment)} parameter"); - } - - WriteVerbose($"Using default environment as retrieved '{environmentName}'"); - } if (ParameterSpecified(nameof(Identity))) { diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs index ab68e25d4..14bef2536 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs @@ -10,7 +10,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsCommon.Get, "PnPFlowOwner")] public class GetFlowOwner : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -21,7 +21,7 @@ public class GetFlowOwner : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; if (string.IsNullOrEmpty(environmentName)) { throw new PSArgumentException("Environment not found.", nameof(Environment)); diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs index 98a5caab1..4ea39df8d 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlowRun.cs @@ -10,7 +10,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsCommon.Get, "PnPFlowRun")] public class GetFlowRun : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -22,7 +22,7 @@ public class GetFlowRun : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; if (string.IsNullOrEmpty(environmentName)) { throw new PSArgumentException("Environment not found."); diff --git a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs index c02b4e9ac..274748351 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlow.cs @@ -10,7 +10,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsCommon.Remove, "PnPFlow")] public class RemoveFlow : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -28,7 +28,7 @@ public class RemoveFlow : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; var flowName = Identity.GetName(); if (Force || ShouldContinue($"Remove flow with name '{flowName}'?", "Remove flow")) diff --git a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs index cfec6f584..7db4b26f0 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/RemoveFlowOwner.cs @@ -10,7 +10,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsCommon.Remove, "PnPFlowOwner")] public class RemoveFlowOwner : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -27,7 +27,7 @@ public class RemoveFlowOwner : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; if (string.IsNullOrEmpty(environmentName)) { throw new PSArgumentException("Environment not found.", nameof(Environment)); diff --git a/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs b/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs index c4ea783de..e9a453c96 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/RestartFlowRun.cs @@ -12,7 +12,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsLifecycle.Restart, "PnPFlowRun")] public class RestartFlowRun : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -27,7 +27,7 @@ public class RestartFlowRun : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; if (string.IsNullOrEmpty(environmentName)) { throw new PSArgumentException("Environment not found."); diff --git a/src/Commands/PowerPlatform/PowerAutomate/RestoreFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/RestoreFlow.cs new file mode 100644 index 000000000..329fec773 --- /dev/null +++ b/src/Commands/PowerPlatform/PowerAutomate/RestoreFlow.cs @@ -0,0 +1,39 @@ +using PnP.PowerShell.Commands.Base; +using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Utilities; +using PnP.PowerShell.Commands.Utilities.REST; +using System; +using System.Management.Automation; + +namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate +{ + [Cmdlet(VerbsData.Restore, "PnPFlow")] + public class RestoreFlow : PnPAzureManagementApiCmdlet + { + [Parameter(Mandatory = false)] + public PowerPlatformEnvironmentPipeBind Environment; + + [Parameter(Mandatory = true)] + public PowerAutomateFlowPipeBind Identity; + + protected override void ExecuteCmdlet() + { + string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment); + + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; + var flowName = Identity.GetName(); + + WriteVerbose($"Restoring soft-deleted flow {flowName} from environment {environmentName}"); + + try + { + RestHelper.Post(Connection.HttpClient, $"{baseUrl}/providers/Microsoft.ProcessSimple/scopes/admin/environments/{environmentName}/flows/{flowName}/restore?api-version=2016-11-01", AccessToken); + WriteVerbose($"Flow with name {flowName} restored"); + } + catch(Exception ex) + { + throw new Exception($"Failed to restore flow with name {flowName} from environment {environmentName} with exception: {ex.Message}", ex); + } + } + } +} \ No newline at end of file diff --git a/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs b/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs index b8c9afef5..0b227421d 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs @@ -10,7 +10,7 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate [Cmdlet(VerbsLifecycle.Stop, "PnPFlowRun")] public class StopFlowRun : PnPAzureManagementApiCmdlet { - [Parameter(Mandatory = true)] + [Parameter(Mandatory = false)] public PowerPlatformEnvironmentPipeBind Environment; [Parameter(Mandatory = true)] @@ -24,7 +24,7 @@ public class StopFlowRun : PnPAzureManagementApiCmdlet protected override void ExecuteCmdlet() { - var environmentName = Environment.GetName(); + var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name; if (string.IsNullOrEmpty(environmentName)) { throw new PSArgumentException("Environment not found."); diff --git a/src/Commands/Utilities/PowerPlatformUtility.cs b/src/Commands/Utilities/PowerPlatformUtility.cs index 0930ad943..aff64fcc8 100644 --- a/src/Commands/Utilities/PowerPlatformUtility.cs +++ b/src/Commands/Utilities/PowerPlatformUtility.cs @@ -1,17 +1,25 @@ -using PnP.Framework; -using System; -using System.Collections.Generic; +using System.Management.Automation; +using PnP.Framework; +using PnP.PowerShell.Commands.Utilities.REST; +using PnP.PowerShell.Commands.Base; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using PnP.PowerShell.Commands.Utilities.Auth; namespace PnP.PowerShell.Commands.Utilities { + /// + /// Utility class for working with the Power Platform + /// internal static class PowerPlatformUtility { + /// + /// Returns the BaseUrl for calling into the Power Automate APIs based on the Azure Environment + /// + /// Azure Environment to indicate the type of cloud to target + /// Base URL for calling into Power Automate APIs public static string GetPowerAutomateEndpoint(AzureEnvironment environment) { - return (environment) switch + return environment switch { AzureEnvironment.Production => "https://api.flow.microsoft.com", AzureEnvironment.Germany => "https://api.flow.microsoft.com", @@ -24,9 +32,14 @@ public static string GetPowerAutomateEndpoint(AzureEnvironment environment) }; } + /// + /// Returns the BaseUrl for calling into the Power Apps APIs based on the Azure Environment + /// + /// Azure Environment to indicate the type of cloud to target + /// Base URL for calling into Power Apps APIs public static string GetPowerAppsEndpoint(AzureEnvironment environment) { - return (environment) switch + return environment switch { AzureEnvironment.Production => "https://api.powerapps.com", AzureEnvironment.Germany => "https://api.powerapps.com", @@ -39,9 +52,14 @@ public static string GetPowerAppsEndpoint(AzureEnvironment environment) }; } + /// + /// Returns the BaseUrl for calling into the Business Applications APIs based on the Azure Environment + /// + /// Azure Environment to indicate the type of cloud to target + /// Base URL for calling into Business Applications APIs public static string GetBapEndpoint(AzureEnvironment environment) { - return (environment) switch + return environment switch { AzureEnvironment.Production => "https://api.bap.microsoft.com", AzureEnvironment.Germany => "https://api.bap.microsoft.com", @@ -53,5 +71,25 @@ public static string GetBapEndpoint(AzureEnvironment environment) _ => "https://api.bap.microsoft.com" }; } + + /// + /// Returns the default Power Platform environment + /// + /// The cmdlet from which this is being requested + /// The connection to use to retrieve the default + /// Optional access token to use to retrieve the default environment. When omitted, it will try to retrieve an access token for the call itself. + /// The type of cloud to communicate with + /// + public static Model.PowerPlatform.Environment.Environment GetDefaultEnvironment(Cmdlet cmdlet, PnPConnection connection, AzureEnvironment azureEnvironment, string accessToken = null) + { + cmdlet.WriteVerbose("Retrieving default Power Platform environment"); + + // If we don't have an access token yet, try to retrieve one + accessToken ??= TokenHandler.GetAccessToken(cmdlet, $"{Endpoints.GetArmEndpoint(connection)}/.default", connection); + + // Request the available environments and try to define the one marked as default + string baseUrl = GetPowerAutomateEndpoint(azureEnvironment); + return GraphHelper.GetResultCollection(cmdlet, connection, $"{baseUrl}/providers/Microsoft.ProcessSimple/environments?api-version=2016-11-01", accessToken).FirstOrDefault(e => e.Properties.IsDefault.GetValueOrDefault(false)); + } } }