I have an HTA that I'm writing that writes and calls a PowerShell script. The PS script interrogates Exchange to find who has ActiveSync enabled. This is used later in the main script for looking at ActiveSync devices and controlling them. The PS script works perfectly when run as a stand-alone PS script.
When I open the HTA in my editor (I use HtaEdit from and run the HTA, the PS script runs perfectly.
When I run the HTA directly the PS script fails. The error message is:
[red]
[/red]
Any ideas why this PS script fails when it runs from within the HTA?
The command I am using in the HTA to run the PS script is:
When I open the HTA in my editor (I use HtaEdit from and run the HTA, the PS script runs perfectly.
When I run the HTA directly the PS script fails. The error message is:
[red]
Code:
File C:\ActiveSyncUsers\ActiveSyncUsers.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 cahr:42
+ & {C:\ActiveSyncUsers\ActiveSyncUsers.ps1 <<<< }
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Any ideas why this PS script fails when it runs from within the HTA?
The command I am using in the HTA to run the PS script is:
Code:
strPowershellScript = "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin" & vbCrLf & _
"Get-ActiveSyncDeviceStatistics -Mailbox " & Identity & " | Select DeviceID, DeviceType | fl | out-file C:\ActiveSyncUsers\ActiveSyncUsers.txt"
RunPowershell strPowershellScript
Sub RunPowershell(Script)
Set objFile = objFSO.OpenTextFile("C:\ActiveSyncUsers\ActiveSyncUsers.ps1",ForWriting,Overwrite,Unicode)
objFile.Write Script
objFile.Close
objShell.Run "Powershell -command ""& {C:\ActiveSyncUsers\ActiveSyncUsers.ps1}""",ShowWindow,WaitToFinish
End Sub