Automatically import module on remote PC running powershell 2.0 when connecting with WinRM
i use script connect remote pcs not on domain. these computers running powershell 2.0 , have carbon module added modules folder. because powershell 2.0, looking way have these modules imported when connect following script.
i've done research , looks have use invoke-command not sure how use when connecting remote pc.
# create $pw variable save password secured string.
$pw = convertto-securestring -asplaintext -force -string *password*
# create $compname variable prompt target computer name.
$compname = read-host "computer name use enter-pssession"
# create $cred variable combine username , password credentials.
$cred = new-object -typename system.management.automation.pscredential -argumentlist $compname\"winrm",$pw
# $session intitalizes enter-pssession use computername, on port 80 using credentials.
$session = enter-pssession -computername $compname -port 80 -credential $cred
figured out:
# create $pw variable save *password* secured string.
$pw = convertto-securestring -asplaintext -force -string *password*
# create $compname variable prompt target computer name.
$compname = read-host "computer name use enter-pssession"
# create $cred variable combine username , password credentials.
$cred = new-object -typename system.management.automation.pscredential -argumentlist $compname\"winrm",$pw
# $session create new persistent pssession
$session = new-pssession -computername $compname -port 80 -credential $cred
# import carbon module in new session
invoke-command -session $session -scriptblock {import-module carbon}
# enter new session
enter-pssession -session $session
Windows Server > Windows PowerShell
Comments
Post a Comment