i need install application in several remote servers in quiet mode. have created script (installer.ps1) below using powershell v3.0:
param( [string] $servernamefilepath = $(throw "provide path of text file contains server names"), [string] $installerfolderpath = $(throw "provide installer folder path. should network location"), [string] $username = $(throw "provide user name"), [string] $password= $(throw "provide password") ) function installapp { $secpasswd = convertto-securestring $password -asplaintext -force $mycreds = new-object system.management.automation.pscredential ($username, $secpasswd) $scrblock = {param($installerfolderpath) $exepath = join-path $installerfolderpath "serverreleasemanager.exe"; & $exepath /q;} invoke-command -computername (get-content servers.txt) -credential $mycreds $scrblock -argumentlist $installerfolderpath } installapp -servernamefilepath $servernamefilepath -installerfolderpath $installerfolderpath -username $username -password $password
then call script below (installer folder path can have white spaces , executable serverreleasemanager.exe accepts argument):
.\installer.ps1 -servernamefilepath servers.txt -installerfolderpath "\\testserver01\public\stable applications\server release manager update 2\2.7" -username "domain\user" -password "test123"
i getting below commandnotfoundexception
always:
the term '\\testserver01\public\stable applications\server release manager update 2\2.7\serverreleasemanager.exe' not recognized name of cmdlet, function, script file, or operable program. check spelling of name, or if path included, verify path correct , try again.
i have tried other options using -filepath
invoke-command
same error. blocked here. can please let me know why error has shown? how resolve error? or there better ways deal this. help.
sounds double-hop authentication issue. once you're remoted server, can't access file share on third server because can't pass kerberos-based authentication it.
you try copying share remote server, first (this has done on computer executing script), , in scriptblock refer (now local) path.
you set credssp isn't great idea purpose.
basically, need avoid connecting 1 machine, connecting through connection.
code implements workaround i'm describing:
param( [string] $servernamefilepath = $(throw "provide path of text file contains server names"), [string] $installerfolderpath = $(throw "provide installer folder path. should network location"), [string] $username = $(throw "provide user name"), [string] $password= $(throw "provide password") ) function installapp { $secpasswd = convertto-securestring $password -asplaintext -force $mycreds = new-object system.management.automation.pscredential ($username, $secpasswd) $scrblock = {param($installerfolderpath) $exepath = join-path $installerfolderpath "serverreleasemanager.exe"; & $exepath /q;} get-content servers.txt | foreach-item { $remotedest = "\\$_\c`$\some\temp\folder" $localdest = "c:\some\temp\folder" | join-path -childpath ($installerfolderpath | split-path -leaf) try { copy-item -path $installerfolderpath -destination $dest -force invoke-command -computername $_ -credential $mycreds $scrblock -argumentlist $localdest { remove-item $remotedest -force -erroraction ignore } } } installapp -servernamefilepath $servernamefilepath -installerfolderpath $installerfolderpath -username $username -password $password
notes
- this untested.
- as mentioned swonkie, should set parameters mandatory if that's you're looking achieve (not addressed in code).
- you shouldn't pass separate plain text user name , password parameters , convert them credential object. instead pass single
[pscredential]
parameter. can use default value prompts,[pscredential] $cred = (get-credential)
. (this not addressed in code either).