首页 > 解决方案 > 在 hta 中加载 Windows 时启动 PsSession

问题描述

我有一个 500 多行的 vb 脚本。HR 正在使用它来设置一些 AD 属性。现在我需要使用 Exchange Powershell 管理工具的 Set-UserPhoto cmdlet。我不想在 powershell 中重写所有脚本。在脚本启动时,我想调用加载非常慢的 Exchange Powershell。然后在脚本调用 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

按保存按钮时,它无法识别 Set-UserPhoto cmdlet。如何保持从第一个命令到脚本结束的第一个 powershell 会话?

标签: powershellvbscripthtapowershell-remotingexchange-management-shell

解决方案


推荐阅读