Powershell Script to run as a shortcut

Hello all,

 

I am attempting to have a powershell script run as a shortcut to output some simple information to a text file.

I have created this one line script named ipscript.ps1

get-netipaddress -addressfamily IPv4 | format-table > $($env:userprofile + '\Desktop\info.txt')

 

Then I created a shortcut and modified the target in the shortcut.

as such

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File “C:\Software\ipscript.ps1”

 

After double clicking the shortcut nothing happens and no file is output. If I run the one line script by itself in powershell the file is created.

 

Can anyone point out to me what could be wrong and how I can resolve it? I thank you in advance.

 

For a “one liner” you don’t need a script file. You can put everything to a command line like this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowStyle Minimized “& {Get-NetIPAddress -AddressFamily IPv4 | Out-File -FilePath (Join-Path -Path $($ENV:USERPROFILE) -ChildPath ‘desktop\info.txt’ )}”

Of course your desktop has to be set up to display icons. :wink:

If you post code, please format it as code using the code tag button right on top of the edit window of the post editor. Thanks.