Hey guys,
I also made two handy scripts to auto-delete the bindings in .dyn files. You need to create one .bat and one .ps1 file. So a Batch and a PowerShell-File.
The Batch-File executes the PowerShell-File on double-click. The PowerShell-File deletes all Bindings in all .dyn files wihtin the same folder where the ps1 is located. Do not rename both files as the names are being referred in the code unless you know how to change the code accordingly. So the easiest way is to copy both files into the same folder where your .dyn files are located and just double click the .bat.
Attention: Be aware that you maybe have to allow execution of PowerShell-Scripts on your machine. Otherwise the PowerShell-Script won’t execute.
The Filenames (incl. extensions) are:
“ExecutePowerShell.bat” and “PS_Script_DeleteBindingsInDynamoFile.ps1”
Here is the Code for the .bat:
@ECHO OFF
SET ThisScriptDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptDirectory%PS_Script_DeleteBindingsInDynamoFile.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%'";
Here is the Code for the .ps1:
$path = $MyInvocation.MyCommand.Path
$path = Split-Path $path -Parent
$files = Get-ChildItem -Path $path -Filter *.dyn
<#
ForEach ($file in $files){
If ($file.Name.Contains("new")){
Remove-Item -Path $file.FullName
}
}
#>
$files = Get-ChildItem -Path $path -Filter *.dyn
ForEach ($file in $files){
#$NewName = $file.FullName -replace ".dyn", "_new.dyn"
#Copy-Item -path $file.FullName -Destination $NewName
(Get-Content -Path $file.FullName -Raw) -replace "(?ms)Bindings.*?]", "Bindings`": []" |
Set-Content -Path $file.FullName
}