r/PowerShell • • 2h ago

Script Sharing [ Removed by moderator ]

[removed] — view removed post

0 Upvotes

10 comments sorted by

•

u/PowerShell-ModTeam 18m ago

DO NOT post malicious scripts. This includes anything without readable code, obfuscated targets, or anything that could be construed as something with a harmful payload. Posting malicous scripts FOR ANY REASON will result in an immediate ban.

14

u/MSgtGunny 1h ago

directly invoking shell scripts hosted on untrusted platforms without reviewing its contents is an awful security practice that should not be promoted.

-6

u/sashag90 1h ago

There is a disclaimer on the site regarding this - I ask people to read the script before launching it.

1

u/MonkeyNin 1h ago

Safety tip: Remember don't run code like https://getshell.pw/sh | bash or https://getshell.pw/sh | iex` unless you trust the author.

for docker.ps1 you don't need Invoke-Expression or Join-String to run docker here

Build an array where spaces create a new element:

$commandToInvoke = @(
    "docker",
    "run",
    "--rm",
    "--name", 
    "$( (New-Guid).ToString() )",
    "--interactive",
    "--tty",
    
    # ... 
    
    "--env", "TERM=xterm-256color",
    "--env", "DOTFILES_DEBUG=true",
    "--network=host"
)

& $commandToInvoke

instead of:

$commandToInvoke = @(
    "docker run",
    "--rm",
    "--name $((New-Guid).ToString())",

You can make it safer by ignoring functions named docker. Otherwise you could end up calling that instead.

$cmd = Get-Command 'docker' -CommandType Application -TotalCount 1 -ErrorAction Stop

$CmdArgs = @( 'docker', 'run', '--rm' ) # ...
& $cmd @CmdArgs

1

u/sashag90 1h ago

Thanks, I'll apply it in my scripts

1

u/g3n3 53m ago

Neat. With the lack of msi, I could see a windows variant being important.

1

u/sashag90 47m ago

I thought about, maybe it will be my next step :)

2

u/g3n3 45m ago

On nix, id probably use brew anyway. Scoop for windows is handy too. The intermediary is updating the admin pwsh on windows.

2

u/g3n3 43m ago

Though brew without sudo is kind of busted. This light probe more important for full admin less installs. Scoop is superior on windows in this way. Nothing like it on nix.

2

u/g3n3 42m ago

https://mise.jdx.dev appears to be the closest to scoop on nix.