From 549169e6bb387cddc8893390d8e3120dd3cc8eb0 Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Tue, 28 May 2024 23:19:17 +0200 Subject: [PATCH 1/3] Client credentials now work #74 Crazy fast winget package search --- .../Commands/BaseIntuneCmdlet.cs | 46 +- .../Commands/SearchWtWinGetPackage.cs | 46 ++ .../Svrooij.WinTuner.CmdLets.dll-Help.xml | 420 ++++++++++++++++++ .../docs/Deploy-WtMsStoreApp.md | 40 +- .../docs/Deploy-WtWin32App.md | 44 +- .../docs/Get-WtWin32Apps.md | 34 +- .../docs/Remove-WtWin32App.md | 34 +- .../docs/Search-WtWinGetPackage.md | 74 +++ .../docs/Svrooij.WinTuner.CmdLets.md | 3 + .../docs/Update-WtIntuneApp.md | 34 +- 10 files changed, 747 insertions(+), 28 deletions(-) create mode 100644 src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs create mode 100644 src/Svrooij.WinTuner.CmdLets/docs/Search-WtWinGetPackage.md diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs b/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs index 61d3253..55261ed 100644 --- a/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs +++ b/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs @@ -15,6 +15,7 @@ namespace Svrooij.WinTuner.CmdLets.Commands; public abstract class BaseIntuneCmdlet : DependencyCmdlet { private const string DefaultClientId = "d5a8a406-3b1d-4069-91cc-d76acdd812fe"; + private const string DefaultClientCredentialScope = "https://graph.microsoft.com/.default"; /// /// @@ -25,7 +26,7 @@ public abstract class BaseIntuneCmdlet : DependencyCmdlet ValueFromPipeline = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Use a managed identity to connect to Intune")] - public bool UseManagedIdentity { get; set; } + public bool UseManagedIdentity { get; set; } = Environment.GetEnvironmentVariable("AZURE_USE_MANAGED_IDENTITY")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true; /// /// @@ -36,7 +37,7 @@ public abstract class BaseIntuneCmdlet : DependencyCmdlet ValueFromPipeline = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Use default Azure Credentials from Azure.Identity to connect to Intune")] - public bool UseDefaultAzureCredential { get; set; } + public bool UseDefaultAzureCredential { get; set; } = Environment.GetEnvironmentVariable("AZURE_USE_DEFAULT_CREDENTIALS")?.Equals("true", StringComparison.OrdinalIgnoreCase) == true; /// /// @@ -47,7 +48,7 @@ public abstract class BaseIntuneCmdlet : DependencyCmdlet ValueFromPipeline = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Use a token from another source to connect to Intune")] - public string? Token { get; set; } + public string? Token { get; set; } = Environment.GetEnvironmentVariable("AZURE_TOKEN"); /// /// @@ -105,6 +106,17 @@ public abstract class BaseIntuneCmdlet : DependencyCmdlet HelpMessage = "Specify the client secret, mandatory for Client Credentials flow. Loaded from `AZURE_CLIENT_SECRET`")] public string? ClientSecret { get; set; } = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET"); + /// + /// + /// + [Parameter( + Mandatory = false, + Position = 40, + ValueFromPipeline = false, + ValueFromPipelineByPropertyName = false, + HelpMessage = "Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All`")] + public string[]? Scopes { get; set; } = Environment.GetEnvironmentVariable("AZURE_SCOPES")?.Split(' '); + /// /// /// @@ -119,6 +131,7 @@ internal void ValidateAuthenticationParameters() if (UseManagedIdentity || UseDefaultAzureCredential) { + Scopes ??= new[] { DefaultClientCredentialScope }; return; } @@ -127,6 +140,12 @@ internal void ValidateAuthenticationParameters() return; } + if (!string.IsNullOrEmpty(ClientId) && !string.IsNullOrEmpty(ClientSecret) && !string.IsNullOrEmpty(TenantId)) + { + Scopes ??= new[] { DefaultClientCredentialScope }; + return; + } + throw new ArgumentException($"Use `{nameof(Token)}`, `{nameof(UseManagedIdentity)}`, `{nameof(UseDefaultAzureCredential)}` or `{nameof(Username)}` to select the graph connection type", nameof(ParameterSetName)); } @@ -137,7 +156,7 @@ internal IAuthenticationProvider CreateAuthenticationProvider(string[]? scopes = return new WingetIntune.Internal.Msal.StaticAuthenticationProvider(Token); } - var scope = (scopes ?? DefaultScopes)[0]; + var scope = (Scopes ?? scopes ?? DefaultScopes)[0]; if (UseManagedIdentity || UseDefaultAzureCredential) { @@ -148,16 +167,19 @@ internal IAuthenticationProvider CreateAuthenticationProvider(string[]? scopes = return new Microsoft.Graph.Authentication.AzureIdentityAuthenticationProvider(credentials, null, null, scope); } - if (!string.IsNullOrEmpty(ClientId) && !string.IsNullOrEmpty(ClientSecret) && !string.IsNullOrEmpty(TenantId)) + if (!string.IsNullOrEmpty(ClientId) && !string.IsNullOrEmpty(TenantId)) { - return new Microsoft.Graph.Authentication.AzureIdentityAuthenticationProvider(new Azure.Identity.ClientSecretCredential(TenantId, ClientId, ClientSecret, new Azure.Identity.ClientSecretCredentialOptions - { - TokenCachePersistenceOptions = new Azure.Identity.TokenCachePersistenceOptions + if (!string.IsNullOrEmpty(ClientSecret)) { + return new Microsoft.Graph.Authentication.AzureIdentityAuthenticationProvider(new Azure.Identity.ClientSecretCredential(TenantId, ClientId, ClientSecret, new Azure.Identity.ClientSecretCredentialOptions { - Name = "WinTuner-PowerShell-CC", - UnsafeAllowUnencryptedStorage = true, - } - }), scopes: new[] { scope }); + TokenCachePersistenceOptions = new Azure.Identity.TokenCachePersistenceOptions + { + Name = "WinTuner-PowerShell-CC", + UnsafeAllowUnencryptedStorage = true, + } + }), scopes: scope); + } + } // Alternative interactive authentication in case the broker is not working as expected. diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs b/src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs new file mode 100644 index 0000000..98cb243 --- /dev/null +++ b/src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs @@ -0,0 +1,46 @@ +using Svrooij.PowerShell.DependencyInjection; +using System; +using System.Management.Automation; +using System.Threading; +using System.Threading.Tasks; + +namespace Svrooij.WinTuner.CmdLets.Commands; + +/// +/// Search for packages in winget +/// Search for WinGet packages, but faster +/// +/// +/// Search for 'fire', did I tell you it's fast? +/// Search-WtWinGetPackage fire +/// +[Cmdlet(VerbsCommon.Search, "WtWinGetPackage", HelpUri = "https://wintuner.app/docs/wintuner-powershell/Search-WtWingetPackage")] +[OutputType(typeof(Winget.CommunityRepository.Models.WingetEntry[]))] +public class SearchWtWinGetPackage : DependencyCmdlet +{ + /// + /// + /// + [Parameter( + Mandatory = true, + Position = 0, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Part of the package ID, 2 characters minimum")] + public string? PackageId { get; set; } + + [ServiceDependency] + private Winget.CommunityRepository.WingetRepository wingetRepository; + + /// + public override async Task ProcessRecordAsync(CancellationToken cancellationToken) + { + if (string.IsNullOrWhiteSpace(PackageId) || PackageId.Length <= 1) + { + throw new ArgumentException("PackageId is required"); + } + var packages = await wingetRepository.SearchPackage(PackageId ?? throw new ArgumentNullException(nameof(PackageId)), cancellationToken); + + WriteObject(packages); + } +} diff --git a/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml b/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml index a0308c9..a3e2e15 100644 --- a/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml +++ b/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml @@ -123,6 +123,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + Deploy-WtMsStoreApp @@ -234,6 +258,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -357,6 +405,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -570,6 +642,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + Deploy-WtWin32App @@ -705,6 +801,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + Deploy-WtWin32App @@ -864,6 +984,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -1071,6 +1215,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -1268,6 +1436,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -1403,6 +1595,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -1976,6 +2192,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -2087,6 +2327,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -2129,6 +2393,114 @@ + + + Search-WtWinGetPackage + Search + WtWinGetPackage + + Search for packages in winget + + + + Search for WinGet packages, but faster + + + + Search-WtWinGetPackage + + PackageId + + Part of the package ID, 2 characters minimum + + String + + String + + + None + + + ProgressAction + + {{ Fill ProgressAction Description }} + + ActionPreference + + ActionPreference + + + None + + + + + + PackageId + + Part of the package ID, 2 characters minimum + + String + + String + + + None + + + ProgressAction + + {{ Fill ProgressAction Description }} + + ActionPreference + + ActionPreference + + + None + + + + + + System.String + + + + + + + + + + Winget.CommunityRepository.Models.WingetEntry[] + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Search-WtWinGetPackage fire + + Search for fire, did I tell you it's fast? + + + + + + Online Version: + https://wintuner.app/docs/wintuner-powershell/Search-WtWingetPackage + + + Unprotect-IntuneWinPackage @@ -2444,6 +2816,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + @@ -2615,6 +3011,30 @@ None + + NoBroker + + Disable Windows authentication broker + + Boolean + + Boolean + + + None + + + Scopes + + Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + + String[] + + String[] + + + None + diff --git a/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtMsStoreApp.md b/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtMsStoreApp.md index 5f5ec57..9b462d7 100644 --- a/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtMsStoreApp.md +++ b/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtMsStoreApp.md @@ -15,15 +15,17 @@ Create a MsStore app in Intune ### PackageId (Default) ``` Deploy-WtMsStoreApp [-PackageId] [[-UseManagedIdentity] ] - [[-UseDefaultAzureCredential] ] [[-Token] ] [[-Username] ] [[-TenantId] ] - [[-ClientId] ] [[-ClientSecret] ] [-ProgressAction ] [] + [[-UseDefaultAzureCredential] ] [[-Token] ] [-NoBroker ] [[-Username] ] + [[-TenantId] ] [[-ClientId] ] [[-ClientSecret] ] [-Scopes ] + [-ProgressAction ] [] ``` ### SearchQuery ``` Deploy-WtMsStoreApp [-SearchQuery] [[-UseManagedIdentity] ] - [[-UseDefaultAzureCredential] ] [[-Token] ] [[-Username] ] [[-TenantId] ] - [[-ClientId] ] [[-ClientSecret] ] [-ProgressAction ] [] + [[-UseDefaultAzureCredential] ] [[-Token] ] [-NoBroker ] [[-Username] ] + [[-TenantId] ] [[-ClientId] ] [[-ClientSecret] ] [-Scopes ] + [-ProgressAction ] [] ``` ## DESCRIPTION @@ -193,6 +195,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -NoBroker +Disable Windows authentication broker + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Scopes +Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtWin32App.md b/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtWin32App.md index 464798e..b4468e0 100644 --- a/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtWin32App.md +++ b/src/Svrooij.WinTuner.CmdLets/docs/Deploy-WtWin32App.md @@ -16,24 +16,26 @@ Create a Win32Lob app in Intune ``` Deploy-WtWin32App [-App] [-IntuneWinFile] [[-LogoPath] ] [-OverrideAppName ] [-GraphId ] [[-UseManagedIdentity] ] - [-UseDefaultAzureCredential ] [[-Token] ] [[-Username] ] [[-TenantId] ] - [[-ClientId] ] [-ClientSecret ] [-ProgressAction ] [] + [-UseDefaultAzureCredential ] [[-Token] ] [-NoBroker ] [[-Username] ] + [[-TenantId] ] [[-ClientId] ] [-ClientSecret ] [-Scopes ] + [-ProgressAction ] [] ``` ### WinGet ``` Deploy-WtWin32App [-PackageId] [-Version] [-RootPackageFolder] [-OverrideAppName ] [-GraphId ] [[-UseManagedIdentity] ] - [-UseDefaultAzureCredential ] [[-Token] ] [[-Username] ] [[-TenantId] ] - [[-ClientId] ] [-ClientSecret ] [-ProgressAction ] [] + [-UseDefaultAzureCredential ] [[-Token] ] [-NoBroker ] [[-Username] ] + [[-TenantId] ] [[-ClientId] ] [-ClientSecret ] [-Scopes ] + [-ProgressAction ] [] ``` ### PackageFolder ``` Deploy-WtWin32App [-PackageFolder] [-OverrideAppName ] [-GraphId ] [[-UseManagedIdentity] ] [-UseDefaultAzureCredential ] [[-Token] ] - [[-Username] ] [[-TenantId] ] [[-ClientId] ] [-ClientSecret ] - [-ProgressAction ] [] + [-NoBroker ] [[-Username] ] [[-TenantId] ] [[-ClientId] ] + [-ClientSecret ] [-Scopes ] [-ProgressAction ] [] ``` ## DESCRIPTION @@ -305,6 +307,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -NoBroker +Disable Windows authentication broker + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Scopes +Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/src/Svrooij.WinTuner.CmdLets/docs/Get-WtWin32Apps.md b/src/Svrooij.WinTuner.CmdLets/docs/Get-WtWin32Apps.md index 3be19e5..ed4120d 100644 --- a/src/Svrooij.WinTuner.CmdLets/docs/Get-WtWin32Apps.md +++ b/src/Svrooij.WinTuner.CmdLets/docs/Get-WtWin32Apps.md @@ -15,8 +15,8 @@ Get all apps from Intune packaged by WinTuner ``` Get-WtWin32Apps [-Update ] [-Superseded ] [-Superseding ] [[-UseManagedIdentity] ] [[-UseDefaultAzureCredential] ] [[-Token] ] - [[-Username] ] [[-TenantId] ] [[-ClientId] ] [[-ClientSecret] ] - [-ProgressAction ] [] + [-NoBroker ] [[-Username] ] [[-TenantId] ] [[-ClientId] ] + [[-ClientSecret] ] [-Scopes ] [-ProgressAction ] [] ``` ## DESCRIPTION @@ -201,6 +201,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -NoBroker +Disable Windows authentication broker + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Scopes +Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/src/Svrooij.WinTuner.CmdLets/docs/Remove-WtWin32App.md b/src/Svrooij.WinTuner.CmdLets/docs/Remove-WtWin32App.md index 2c5346b..607bcaf 100644 --- a/src/Svrooij.WinTuner.CmdLets/docs/Remove-WtWin32App.md +++ b/src/Svrooij.WinTuner.CmdLets/docs/Remove-WtWin32App.md @@ -14,8 +14,8 @@ Remove an app from Intune ``` Remove-WtWin32App -AppId [[-UseManagedIdentity] ] [[-UseDefaultAzureCredential] ] - [[-Token] ] [[-Username] ] [[-TenantId] ] [[-ClientId] ] - [[-ClientSecret] ] [-ProgressAction ] [] + [[-Token] ] [-NoBroker ] [[-Username] ] [[-TenantId] ] [[-ClientId] ] + [[-ClientSecret] ] [-Scopes ] [-ProgressAction ] [] ``` ## DESCRIPTION @@ -170,6 +170,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -NoBroker +Disable Windows authentication broker + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Scopes +Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). diff --git a/src/Svrooij.WinTuner.CmdLets/docs/Search-WtWinGetPackage.md b/src/Svrooij.WinTuner.CmdLets/docs/Search-WtWinGetPackage.md new file mode 100644 index 0000000..8dfc758 --- /dev/null +++ b/src/Svrooij.WinTuner.CmdLets/docs/Search-WtWinGetPackage.md @@ -0,0 +1,74 @@ +--- +external help file: Svrooij.WinTuner.CmdLets.dll-Help.xml +Module Name: Svrooij.WinTuner.CmdLets +online version: https://wintuner.app/docs/wintuner-powershell/Search-WtWingetPackage +schema: 2.0.0 +--- + +# Search-WtWinGetPackage + +## SYNOPSIS +Search for packages in winget + +## SYNTAX + +``` +Search-WtWinGetPackage [-PackageId] [-ProgressAction ] [] +``` + +## DESCRIPTION +Search for WinGet packages, but faster + +## EXAMPLES + +### Example 1 +``` +PS C:\> Search-WtWinGetPackage fire +``` + +Search for fire, did I tell you it's fast? + +## PARAMETERS + +### -PackageId +Part of the package ID, 2 characters minimum + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### -ProgressAction +{{ Fill ProgressAction Description }} + +```yaml +Type: ActionPreference +Parameter Sets: (All) +Aliases: proga + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String +## OUTPUTS + +### Winget.CommunityRepository.Models.WingetEntry[] +## NOTES + +## RELATED LINKS diff --git a/src/Svrooij.WinTuner.CmdLets/docs/Svrooij.WinTuner.CmdLets.md b/src/Svrooij.WinTuner.CmdLets/docs/Svrooij.WinTuner.CmdLets.md index dd02d57..a3992a3 100644 --- a/src/Svrooij.WinTuner.CmdLets/docs/Svrooij.WinTuner.CmdLets.md +++ b/src/Svrooij.WinTuner.CmdLets/docs/Svrooij.WinTuner.CmdLets.md @@ -29,6 +29,9 @@ Create intunewin file from Winget installer ### [Remove-WtWin32App](Remove-WtWin32App.md) Remove an app from Intune +### [Search-WtWinGetPackage](Search-WtWinGetPackage.md) +Search for packages in winget + ### [Unprotect-IntuneWinPackage](Unprotect-IntuneWinPackage.md) Decrypt an IntuneWin package diff --git a/src/Svrooij.WinTuner.CmdLets/docs/Update-WtIntuneApp.md b/src/Svrooij.WinTuner.CmdLets/docs/Update-WtIntuneApp.md index 812caf4..a164e10 100644 --- a/src/Svrooij.WinTuner.CmdLets/docs/Update-WtIntuneApp.md +++ b/src/Svrooij.WinTuner.CmdLets/docs/Update-WtIntuneApp.md @@ -16,8 +16,8 @@ Update an app in Intune Update-WtIntuneApp -AppId [-Categories ] [-AvailableFor ] [-RequiredFor ] [-UninstallFor ] [-EnableAutoUpdate ] [[-UseManagedIdentity] ] [[-UseDefaultAzureCredential] ] [[-Token] ] - [[-Username] ] [[-TenantId] ] [[-ClientId] ] [[-ClientSecret] ] - [-ProgressAction ] [] + [-NoBroker ] [[-Username] ] [[-TenantId] ] [[-ClientId] ] + [[-ClientSecret] ] [-Scopes ] [-ProgressAction ] [] ``` ## DESCRIPTION @@ -247,6 +247,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -NoBroker +Disable Windows authentication broker + +```yaml +Type: Boolean +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Scopes +Specify the scopes to request, default is `DeviceManagementConfiguration.ReadWrite.All`, `DeviceManagementApps.ReadWrite.All` + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). From 2cbdf4427e55e97f29981c65d67cbb39a87371af Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Tue, 28 May 2024 23:31:45 +0200 Subject: [PATCH 2/3] Adding tests for Search-WtWinGetPackage --- .vscode/launch.json | 8 ++++++++ .vscode/tasks.json | 12 +++++++++++- .../Commands/BaseIntuneCmdlet.cs | 5 +++-- .../Commands/SearchWtWinGetPackage.cs | 2 +- .../Search-WtWinGetPackage.Tests.ps1 | 19 +++++++++++++++++++ .../WinTuner.Cmdlets.Tests/WinTuner.Tests.ps1 | 5 ----- 6 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 diff --git a/.vscode/launch.json b/.vscode/launch.json index f258c19..65032fd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,14 @@ "script": "${file}", "cwd": "${fileDirname}" }, + { + "name": "Build and Load PowerShell Module", + "type": "PowerShell", + "request": "launch", + "preLaunchTask": "dotnet: build-module", // replace with your actual build task name + "script": "Import-Module .\\bin\\Debug\\net6.0\\WinTuner.psd1 -Verbose", // replace with your actual script path + "cwd": "${workspaceFolder}\\src\\Svrooij.WinTuner.CmdLets" + }, { "name": ".NET Core Package Microsoft SQL Server Management Studio", "type": "coreclr", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index cbe96f3..81cfbe4 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -10,6 +10,16 @@ "isDefault": true }, "problemMatcher": "$msCompile" - } + }, + { + "type": "shell", + "label": "dotnet: build-module", + "command": "dotnet build ${workspaceFolder}\\src\\Svrooij.WinTuner.CmdLets\\Svrooij.WinTuner.CmdLets.csproj", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$msCompile" + } ] } \ No newline at end of file diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs b/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs index 55261ed..bd9b5b5 100644 --- a/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs +++ b/src/Svrooij.WinTuner.CmdLets/Commands/BaseIntuneCmdlet.cs @@ -169,7 +169,8 @@ internal IAuthenticationProvider CreateAuthenticationProvider(string[]? scopes = if (!string.IsNullOrEmpty(ClientId) && !string.IsNullOrEmpty(TenantId)) { - if (!string.IsNullOrEmpty(ClientSecret)) { + if (!string.IsNullOrEmpty(ClientSecret)) + { return new Microsoft.Graph.Authentication.AzureIdentityAuthenticationProvider(new Azure.Identity.ClientSecretCredential(TenantId, ClientId, ClientSecret, new Azure.Identity.ClientSecretCredentialOptions { TokenCachePersistenceOptions = new Azure.Identity.TokenCachePersistenceOptions @@ -179,7 +180,7 @@ internal IAuthenticationProvider CreateAuthenticationProvider(string[]? scopes = } }), scopes: scope); } - + } // Alternative interactive authentication in case the broker is not working as expected. diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs b/src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs index 98cb243..86d05ed 100644 --- a/src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs +++ b/src/Svrooij.WinTuner.CmdLets/Commands/SearchWtWinGetPackage.cs @@ -40,7 +40,7 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke throw new ArgumentException("PackageId is required"); } var packages = await wingetRepository.SearchPackage(PackageId ?? throw new ArgumentNullException(nameof(PackageId)), cancellationToken); - + WriteObject(packages); } } diff --git a/tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 new file mode 100644 index 0000000..9e08dbf --- /dev/null +++ b/tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 @@ -0,0 +1,19 @@ + +Describe 'Search-WtWinGetPackage' { + It 'Should be available' { + $cmdlet = Get-Command -Name 'Search-WtWinGetPackage' + $cmdlet.CommandType | Should -Be 'Cmdlet' + } + + It 'Should return a list of packages' { + $packages = Search-WtWinGetPackage -Name 'Firef' + $packages | Should -Not -BeNullOrEmpty + } + + It 'Should return a list of packages with a specific name' { + $packages = Search-WtWinGetPackage -Name 'Firef' + $packages | ForEach-Object { + $_.PackageId | Should -Match 'Firef' + } + } +} \ No newline at end of file diff --git a/tests/WinTuner.Cmdlets.Tests/WinTuner.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/WinTuner.Tests.ps1 index ed0d448..6e35400 100644 --- a/tests/WinTuner.Cmdlets.Tests/WinTuner.Tests.ps1 +++ b/tests/WinTuner.Cmdlets.Tests/WinTuner.Tests.ps1 @@ -8,11 +8,6 @@ BeforeDiscovery { } Describe "WinTuner Module tests" { - - It "should have at least 8 commands" { - Get-Command -Module WinTuner | Should -HaveCount 8 - } - Context "Command <_>" -ForEach $commands { It "should have a help URI" { $command = Get-Command -Name $_ From b55c026f69883d1e77aab50da3fc94a854306937 Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Tue, 28 May 2024 23:38:00 +0200 Subject: [PATCH 3/3] chore: Fix test for Search-WtWinGetPackage --- .../WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 b/tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 index 9e08dbf..e774797 100644 --- a/tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 +++ b/tests/WinTuner.Cmdlets.Tests/Search-WtWinGetPackage.Tests.ps1 @@ -6,14 +6,14 @@ Describe 'Search-WtWinGetPackage' { } It 'Should return a list of packages' { - $packages = Search-WtWinGetPackage -Name 'Firef' + $packages = Search-WtWinGetPackage 'Firef' $packages | Should -Not -BeNullOrEmpty } It 'Should return a list of packages with a specific name' { - $packages = Search-WtWinGetPackage -Name 'Firef' + $packages = Search-WtWinGetPackage 'Firef' $packages | ForEach-Object { - $_.PackageId | Should -Match 'Firef' + $_.PackageId | Should -Match '(?i)Firef' } } } \ No newline at end of file