Start PsSession on windows load in hta

165 views Asked by At

I have a 500+ lines vb script. It is being used by HR to set some AD attributes. Now I need to use Set-UserPhoto cmdlet of Exchange Powershell Management tools. I don't want to rewrite all script in powershell. On script startup, I want to call Exchange Powershell, which loads very slow. And then during script call Set-UserPhoto.

Set objShell = CreateObject("Wscript.Shell")
Sub window_onload
command = "powershell.exe –ExecutionPolicy Bypass -command ""$session = New-PSSession -configurationname Microsoft.Exchange -connectionuri http://mail/powershell; Import-PSSession $session -CommandName set-userphoto"""
objShell.run command,1,true
End Sub
.
.
Sub Save_button
command2 = "powershell.exe –ExecutionPolicy Bypass -command ""Set-UserPhoto -Identity User -PictureData ([System.IO.File]::ReadAllBytes('D:\pictures\user.jpg')) -Confirm:$false"""
objShell.run command2,1,true
End Sub

On pressing Save button, it doesn't recognize Set-UserPhoto cmdlet. How to keep first powershell session from first command till the end of script?

0

There are 0 answers