Normally, I use the command:
Remove-Item $MyINvocation.InvocationName
to self-delete a script after it's ran. But when I convert it into an EXE, I get the error:
Remove-Item: Cannot bind argument to parameter 'Path' because it is an empty string.
This works when it is a PS1, but no longer works as an EXE.
Self-Deleting Script turned into Exe?
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Self-Deleting Script turned into Exe?
$MyINvocation.InvocationName will not work in a packaged script.
You can look at the Get-ScriptDirectory snippet so you can get an idea how to get the script path.
Here is what you would use:
David
You can look at the Get-ScriptDirectory snippet so you can get an idea how to get the script path.
Here is what you would use:
PowerShell Code
Double-click the code block to select all.if($hostinvocation -ne $null) { $hostinvocation.MyCommand.path } else { $script:MyInvocation.MyCommand.Path }Note: An executable can't delete itself while running in Windows.
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.