Private/_SetupTools.ps1
# # _SetupTools.ps1 # function Install-XrmModule($admin = $false) { $moduleName = "Microsoft.Xrm.Data.Powershell" [version]$moduleVersion = "2.8.14" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { Write-host "Module $moduleName version $moduleVersion or higher not found, installing now" if ($admin) { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -Scope CurrentUser } Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName version $moduleVersion or higher Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } function Install-DevOpsDataModule($admin = $false) { $moduleName = "Microsoft.Xrm.DevOps.Data.Powershell" [version]$moduleVersion = "1.4.2" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { Write-host "Module $moduleName version $moduleVersion or higher not found, installing now" if ($admin) { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -Scope CurrentUser } Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName version $moduleVersion or higher Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } function Install-ConfigMigrationModule($admin = $false) { $moduleName = "Microsoft.Xrm.Tooling.ConfigurationMigration" [version]$moduleVersion = "1.0.0.61" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { Write-host "Module $moduleName version $moduleVersion or higher not found, installing now" if ($admin) { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -Scope CurrentUser } Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName version $moduleVersion or higher Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } function Install-CoreTools { $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $targetNugetExe = ".\nuget.exe" Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe Set-Alias nuget $targetNugetExe -Scope Global ## ##Download CoreTools ## Write-host "Nuget Sources" if (-not $(Get-PackageSource -ProviderName NuGet -ErrorAction Ignore)) { ./nuget sources Add -Name "nuget live" -Source "https://api.nuget.org/v3/index.json" } ./nuget sources ./nuget install Microsoft.CrmSdk.CoreTools -O .\Tools $coreToolsFolder = Get-ChildItem ./Tools | Where-Object { $_.Name -match 'Microsoft.CrmSdk.CoreTools.' } Move-Item .\Tools\$coreToolsFolder\content\bin\coretools\*.* .\Tools\ -Force -ErrorAction SilentlyContinue Remove-Item .\Tools\$coreToolsFolder -Force -Recurse -ErrorAction Ignore } function Install-ConfigMigration { if (!(Test-Path "$env:APPDATA\Microsoft.PowerPlatform.DevOps\ConfigMigration")) { $configDirectory = New-Item -Path "$env:APPDATA\Microsoft.PowerPlatform.Devops\ConfigMigration" -ItemType Directory Write-Host "Installing Configuration Migration Tool" $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $targetNugetExe = ".\nuget.exe" Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe Set-Alias nuget $targetNugetExe -Scope Global ## ##Download Config Migration ## Write-host "Nuget Sources" if (-not $(Get-PackageSource -ProviderName NuGet -ErrorAction Ignore)) { ./nuget sources Add -Name "nuget live" -Source "https://api.nuget.org/v3/index.json" } ./nuget sources ./nuget install Microsoft.CrmSdk.XrmTooling.ConfigurationMigration.Wpf -O .\Tools $configMigFolder = Get-ChildItem ./Tools | Where-Object { $_.Name -match 'Microsoft.CrmSdk.XrmTooling.ConfigurationMigration.Wpf.' } Move-Item .\Tools\$configMigFolder\tools\*.* $env:APPDATA\Microsoft.PowerPlatform.DevOps\ConfigMigration\ -Force -ErrorAction SilentlyContinue Remove-Item .\Tools\$configMigFolder -Force -Recurse -ErrorAction Ignore } else { Write-Host "Configuration Migration Tools already installed" } } function Install-XrmDefinitelyTyped { if (!(Test-Path "$env:APPDATA\Microsoft.PowerPlatform.DevOps\XrmDefinitelyTyped")) { $configDirectory = New-Item -Path "$env:APPDATA\Microsoft.PowerPlatform.Devops\XrmDefinitelyTyped" -ItemType Directory Write-Host "Installing XrmDefinitelyTyped" $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $targetNugetExe = ".\nuget.exe" Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe Set-Alias nuget $targetNugetExe -Scope Global ## ##Download Config Migration ## Write-host "Nuget Sources" if (-not $(Get-PackageSource -ProviderName NuGet -ErrorAction Ignore)) { ./nuget sources Add -Name "nuget live" -Source "https://api.nuget.org/v3/index.json" } ./nuget sources ./nuget install Delegate.XrmDefinitelyTyped -O .\Tools $xdFolder = Get-ChildItem ./Tools | Where-Object { $_.Name -match 'Delegate.XrmDefinitelyTyped.' } Move-Item .\Tools\$xdFolder\content\XrmDefinitelyTyped\*.* $env:APPDATA\Microsoft.PowerPlatform.DevOps\XrmDefinitelyTyped\ -Force -ErrorAction SilentlyContinue Remove-Item .\Tools\$xdFolder -Force -Recurse -ErrorAction Ignore } else { Write-Host "XrmDefinitelyTyped already installed" } } function Install-XrmContext { if (!(Test-Path "$env:APPDATA\Microsoft.PowerPlatform.DevOps\XrmContext")) { $configDirectory = New-Item -Path "$env:APPDATA\Microsoft.PowerPlatform.Devops\XrmContext" -ItemType Directory Write-Host "Installing XrmContext" $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $targetNugetExe = ".\nuget.exe" Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe Set-Alias nuget $targetNugetExe -Scope Global ## ##Download Config Migration ## Write-host "Nuget Sources" if (-not $(Get-PackageSource -ProviderName NuGet -ErrorAction Ignore)) { ./nuget sources Add -Name "nuget live" -Source "https://api.nuget.org/v3/index.json" } ./nuget sources ./nuget install Delegate.XrmContext -O .\Tools $xcFolder = Get-ChildItem ./Tools | Where-Object { $_.Name -match 'Delegate.XrmContext.' } Move-Item .\Tools\$xcFolder\content\XrmContext\*.* $env:APPDATA\Microsoft.PowerPlatform.DevOps\XrmContext\ -Force -ErrorAction SilentlyContinue Remove-Item .\Tools\$xcFolder -Force -Recurse -ErrorAction Ignore } else { Write-Host "XrmContext already installed" } } function Install-XrmDeployModule { $moduleName = "Microsoft.Xrm.Tooling.PackageDeployment.Powershell" [version]$moduleVersion = "3.3.0.928" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { Write-host "Module $moduleName version $moduleVersion or higher not found, installing now" Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -Scope CurrentUser -SkipPublisherCheck Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName version $moduleVersion or higher Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } function Install-XrmToolingPowerShell { $moduleName = "Microsoft.Xrm.Tooling.CrmConnector.PowerShell" [version]$moduleVersion = "3.3.0.928" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { Write-host "Module $moduleName version $moduleVersion or higher not found, installing now" Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -AllowClobber -Scope CurrentUser Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } function Install-PowerAppsCheckerModule($admin = $false) { $moduleName = "Microsoft.PowerApps.Checker.PowerShell" [version]$moduleVersion = "1.0.29" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { if ($admin) { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -Scope CurrentUser } Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName version $moduleVersion or higher Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } function Install-PowerAppsAdmin($admin = $false) { $moduleName = "Microsoft.PowerApps.Administration.PowerShell" [version]$moduleVersion = "2.0.139" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { Write-host "Module $moduleName version $moduleVersion or higher not found, installing now" if ($admin) { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -AllowClobber } else { Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -AllowClobber -Scope CurrentUser } Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName version $moduleVersion or higher Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } function Install-PowerAppsPowerShell { $moduleName = "Microsoft.PowerApps.PowerShell" [version]$moduleVersion = "1.0.20" $module = Get-Module -ListAvailable -Name $moduleName if (!($module.Version -ge $moduleVersion )) { Write-host "Module $moduleName version $moduleVersion or higher not found, installing now" Install-Module -Name $moduleName -MinimumVersion $moduleVersion -Force -AllowClobber -Scope CurrentUser Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } else { Write-host "Module $moduleName Found" if (!(Get-Module -Name $moduleName).Version -eq $moduleVersion) { Import-Module -Name $moduleName -MinimumVersion $moduleVersion -Force } } } $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $PSGallery = Get-PSRepository | Where-Object Name -eq "PSGallery" | Select-Object InstallationPolicy if (-not $PSGallery.InstallationPolicy -eq "Trusted") { Register-PSRepository -Default -ErrorAction SilentlyContinue Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -ErrorAction SilentlyContinue } if (-not $(Get-PackageProvider -Name NuGet -ErrorAction Ignore)) { Install-PackageProvider -Name NuGet -Force -Scope CurrentUser -Confirm:$false } function Install-PAC { if (!(Test-Path "$env:APPDATA\Microsoft.PowerPlatform.DevOps\PACTools")) { Write-Host "Downloading Power Platform CLI..." New-Item -Path "$env:APPDATA\Microsoft.PowerPlatform.Devops\PACTools" -ItemType Directory $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" $targetNugetExe = ".\nuget.exe" Remove-Item .\Tools -Force -Recurse -ErrorAction Ignore Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe Set-Alias nuget $targetNugetExe -Scope Global ## ##Download Power Platform CLI ## Write-host "Nuget Sources" if (-not $(Get-PackageSource -ProviderName NuGet -ErrorAction Ignore)) { ./nuget sources Add -Name "nuget live" -Source "https://api.nuget.org/v3/index.json" } nuget sources nuget install Microsoft.PowerApps.CLI -O .\PAC $toolsFolder = (Get-ChildItem -Filter tools -Recurse -Path .\PAC).FullName Move-Item -Path $toolsFolder -Destination $env:APPDATA\Microsoft.PowerPlatform.DevOps\PACTools -Force -ErrorAction SilentlyContinue Remove-Item .\PAC -Force -Recurse -ErrorAction Ignore } else { Write-Host "PACTools already downloaded" } } |