Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate AppDeployToolkitExtensions.ps1 from v3 to v4 #5

Open
Rudi422 opened this issue Jan 8, 2025 · 2 comments
Open

Migrate AppDeployToolkitExtensions.ps1 from v3 to v4 #5

Rudi422 opened this issue Jan 8, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Rudi422
Copy link

Rudi422 commented Jan 8, 2025

Summary of the new feature / enhancement

With the Convert-ADTDeployment you can convert Deploy-Application.ps1 files. But we have lot of home brew functions in AppDeployToolkitExtensions.ps1 . when trying to convert that it gives an error "Convert-ADTDeployment : The expected if statement was not found in the input script."
Can the convert function be changed so that it is also possible to convert the extensions.ps1. I realize that we will have to do some specific work on it but if this functions could do the bulk then that would be amazing for us.

v4, nice work by the way.

Proposed technical implementation details (optional)

No response

@coder-labeler coder-labeler bot added the enhancement New feature or request label Jan 8, 2025
@DanGough
Copy link
Collaborator

DanGough commented Jan 9, 2025

I will look into adding support for this - in the meantime you can try experimenting with this:

$CustomRulePath = "$((Get-Module PSAppDeployToolkit.Tools -ListAvailable).ModuleBase)\PSScriptAnalyzer\Measure-ADTCompatibility.psm1"
Invoke-ScriptAnalyzer -Path <PathToExtensionsFile> -CustomRulePath $CustomRulePath

To list the changes, and add -Fix to that to actually update the file (making sure you have a backup of course!).

@DanGough DanGough self-assigned this Jan 9, 2025
@Rudi422
Copy link
Author

Rudi422 commented Jan 10, 2025

I did try the code you gave. Without the -Fix it indeed shows all the issues like it should. But with the -Fix the issues are not corrected in the file and I don't see what i am doing wrong here. I am using the following PS version.

Name Value


PSVersion 5.1.22621.4391
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.4391
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

With these modules loaded.

Name Version


PSAppDeployToolkit 4.0.4
PSAppDeployToolkit.Tools 0.2.2
PSScriptAnalyzer 1.23.0

This is the commandline I am using as you suggested.
$CustomRulePath = "$((Get-Module PSAppDeployToolkit.Tools -ListAvailable).ModuleBase)\PSScriptAnalyzer\Measure-ADTCompatibility.psm1"
Invoke-ScriptAnalyzer -Path 'C:\Temp\extensions\PSAppDeployToolkit.Extensions\AppDeployToolkitExtensions.ps1' -CustomRulePath $CustomRulePath -Fix
Any idea what I am doing wrong here?

I tested a bit more and when I have a plain ps1 file without functions defined it works ok.
Plain without functions the Write-Log will be converted to Write-ADTLogEntry.

##===============================================
##
FUNCTION LISTINGS
##*===============================================

Write-Log -Message "This one is not in a function."

##===============================================
##
END FUNCTION LISTINGS
##*===============================================

But as soon that one function is defined then the conversion is not done.
With function, nothing is converted.
##===============================================
##
FUNCTION LISTINGS
##*===============================================

Write-Log -Message "This one is not in a function."

function Set-LogMessage-Test {
Write-Log -Message "This one is in a function."
}

##===============================================
##
END FUNCTION LISTINGS
##*===============================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants