Skip to content

Commit 9b85185

Browse files
committed
Automatically delete initialization script on completion
1 parent 86fb17e commit 9b85185

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

_InitializeRepository.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ If you have made changes to any files you may want to commit them before continu
2828
Write-Information "Removing the temporary template module files since we are done using it to create the template repository files."
2929
RemoveTemporaryModuleDirectory -tempModuleDirectoryPath $tempModuleDirectoryPath
3030

31+
Write-Information "Starting external process to delete this script."
32+
DeleteThisScript
33+
3134
Write-Host -ForegroundColor Green "Repo initialization complete. You can now commit the changes to your repository."
3235
}
3336

@@ -70,4 +73,20 @@ Begin
7073
Remove-Item -Path $tempModuleDirectoryPath -Recurse -Force -ErrorAction SilentlyContinue
7174
}
7275
}
76+
77+
function DeleteThisScript
78+
{
79+
[string] $scriptPath = $MyInvocation.MyCommand.Path
80+
[string] $deleteCommand = "-ExecutionPolicy Bypass -NoProfile -Command `"Start-Sleep -Seconds 1; Remove-Item -Path $scriptPath -Force`""
81+
82+
$powerShellVersion = $PSVersionTable.PSVersion.Major
83+
if ($powerShellVersion -le 5)
84+
{
85+
Invoke-Expression -Command "powershell $deleteCommand"
86+
}
87+
else
88+
{
89+
Invoke-Expression -Command "pwsh $deleteCommand"
90+
}
91+
}
7392
}

0 commit comments

Comments
 (0)