powershell - 在 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 会话?
解决方案
推荐阅读
- spring-boot-actuator - SBA:经过身份验证的 sba 为每个请求创建新会话
- unity3d - 如何配置相机调整宽高
- ios - 如何在 iOS 中验证 HTTP/2 连接池/重用?
- wiremock - 空闲时的 WireMock 内存消耗
- c# - Visual Studio 在新类的开头放置空行,即使类模板中没有
- amazon-web-services - 解释 AWS RDS 监控统计信息
- javascript - 如何在 Angular 单元测试中模拟服务?
- python - 如何在 tkinter 中动态更改标题?
- spring-integration - 使用 Spring 集成确认收到消息
- android - 如果新项目部分离屏,RecyclerView 的项目添加动画将无法正常播放