Home:ALL Converter>How can I run a PowerShell script via SMB remotely?

How can I run a PowerShell script via SMB remotely?

Ask Time:2022-11-24T15:17:36         Author:rocky

Json Formatter

I am trying to run a PowerShell script via SMB connection, but it does not run the script:

smbclient hostname -U username%password -c "Powershell -File run.ps1"

It fails saying:

Powershell: command not found

I want to run a PowerShell script via SMB on a remote server.

linux(from) -> Windows(to)

Author:rocky,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74556929/how-can-i-run-a-powershell-script-via-smb-remotely
stackprotector :

The -c/--command parameter of smbclient is for SMB command strings only, not for arbitrary shell commands. See man pages.\nThese are your available commands:\nsmb: \\> ?\n? allinfo altname archive backup \nblocksize cancel case_sensitive cd chmod \nchown close del deltree dir \ndu echo exit get getfacl \ngeteas hardlink help history iosize \nlcd link lock lowercase ls \nl mask md mget mkdir \nmore mput newer notify open \nposix posix_encrypt posix_open posix_mkdir posix_rmdir \nposix_unlink posix_whoami print prompt put \npwd q queue quit readlink \nrd recurse reget rename reput \nrm rmdir showacls setea setmode \nscopy stat symlink tar tarmode \ntimeout translate unlock volume vuid \nwdel logon listconnect showconnect tcon \ntdis tid utimes logoff .. \n!\n\nYou can use ! <SHELL_COMMAND> for shell commands, but they will be executed locally, not on your remote server.\nIn other words, you cannot execute PowerShell scripts remotely via SMB. Look for other remoting technologies. You will find more than enough examples for PowerShell remoting or SSH here on [SO].",
2022-11-24T08:51:16
Ralph Sch :

Is Powershell Remoting not an option?\nJust use Invoke-Command with either a PSSession object or with -ComputerName <remotecomputer>. It will let you pass files and script blocks but you'll need to pass arguments to script blocks (if any) using -ArgumentList and their position as defined in the script block's PARAM() section.",
2022-11-24T22:23:30
yy