*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build: Powershell Studio 2018 Version 5.5.152
32 or 64 bit version of product: 64 bit
Operating system:
Microsoft Windows 10 Enterprise
10.0.16299 N/A Build 16299
32 or 64 bit OS: 64 bit
Ok. I am at a loss. I have been writing a powershell script with a GUI, and am using background jobs to allow the form to be more responsive, using the functions obtained from the below sapien post:
https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
I have been able to successfully implement this functionality in the past with no issue, however, fairly recently (I am pretty sure it started after the last powershell studio update), either when I am running the deployed source script that I run directly from powershell or a compiled executable, the background jobs just hang and never complete. However, the previous scripts using the same background job functions still process successfully and if I take the background job that the script is hanging on and create the job myself manually (with start-job, receive-job, etc), then it runs successfully. I can only think that this is due to some change in the way that powershell Studio compiles the scripts. The portion that is hanging is form_load event, and while it appears that it processes all of the commands in the jobscript script block, it the content in the "completescript" block never process. Below is the code in question:
Code: Select all
$MainForm_Load = {
#TODO: Initialize Form Controls here
$progressbaroverlay1.Visible = $true
Add-JobTracker -Name Startup -JobScript {
param ($scriptdir,
$scriptnamee
)
$sec = ConvertTo-SecureString 'stuff' -AsPlainText -Force
$necred = New-Object System.Management.Automation.PSCredential -ArgumentList "stuff", $sec
Get-PackageProvider -Name NuGet -ForceBootstrap -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
import-module "C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1" -Force
Update-SessionEnvironment
#install the latest version of the departmodule from the VSTS package feed.
choco upgrade NuGet.commandline -y
Update-SessionEnvironment
NuGet update -self
Install-Module Powershellget -Repository PSGallery -RequiredVersion 1.5.0.0 -Force -AllowClobber
Remove-Module powershellget -Force
Import-Module powershellget -RequiredVersion 1.5.0.0 -Force
If (!(Test-Path "$env:ProgramFiles\WindowsPowerShell\Modules\PoshInternals"))
{
Install-Module PoshInternals -AllowClobber -Force -Repository "PSGallery"
}
Else
{
Update-Module PoshInternals -Force
}
If (!(Test-Path "$env:ProgramFiles\WindowsPowerShell\Modules\AzureRM.KeyVault"))
{
Install-Module AzureRm -AllowClobber -Force -Repository "PSGallery"
}
else
{
Update-Module Azurerm -Force
}
If (!(Test-Path $env:ProgramFiles\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline))
{
Install-Module SharePointPnPPowerShellOnline -AllowClobber -Force -Repository "PSGallery"
}
Else
{
Update-Module SharePointPnPPowerShell* -Force
}
If (!(Test-Path $env:ProgramFiles\WindowsPowerShell\Modules\MSOnline))
{
Install-Module MSOnline -AllowClobber -Force -Repository "PSGallery"
}
Else
{
Update-Module MSOnline -Force
}
$repsource = Get-PackageSource -PackageManagementProvider Nuget -ProviderName PowerShellGet -Force -ForceBootstrap
If ($repsource.Name -notcontains "EE")
{
NuGet Sources Add -Name "EE" -Source "stuff/_packaging/EE/nuget/v2/" -Username "usertoken" -Password 'pippgvuy2txlc3aebry7ke77jqjd3woing7rte5homsaj2iy7lpq' -storePasswordInClearText
}
$psrep = Get-PSRepository -Name "EE" -ErrorAction SilentlyContinue
if ($psrep -eq $null)
{
Register-PSRepository -Name "EE" -SourceLocation "stuff/_packaging/EE/nuget/v2/" -Credential $necred -InstallationPolicy Trusted
}
$instmodule = $null
$repmodule = $null
#test to see if the departmodule is already present on the system. If it is,
#uninstall it.
If (Test-Path $env:ProgramFiles\WindowsPowerShell\Modules\DepartModule)
{
$instmodule = Get-InstalledModule -Name Departmodule
$repmodule = Find-Module -Name DepartModule -Repository EE -Credential $necred
If ([System.Version]$repmodule.Version -gt [System.Version]$instmodule.Version)
{
#Get-Handle -Name "$env:ProgramFiles\WindowsPowerShell\Modules\DepartModule" | Close-Handle -Confirm:$false -ErrorAction SilentlyContinue
Get-Handle -Name "$env:ProgramFiles\WindowsPowerShell\Modules\DepartModule\*" | Close-Handle -Confirm:$false -ErrorAction SilentlyContinue
Uninstall-Module Departmodule -Force -AllVersions
Install-Module DepartModule -Repository "EE" -Force -AllowClobber -Credential $necred
}
}
Else
{
Install-Module DepartModule -Repository "EE" -Force -AllowClobber -Credential $necred
}
Import-Module DepartModule -Force
#test to see if the Remote server administration tools are installed on the system.
#If they are not, install them.
Try
{
Import-Module Activedirectory -Force -ErrorAction Stop
}
Catch
{
$wmi = Get-WmiObject -Class Win32_OperatingSystem -Namespace Root\cimv2 -Property "caption"
If ($wmi.caption -like "*server*")
{
Add-WindowsFeature -Name RSAT-AD-Tools
Add-windowsFeature -Name RSAT-AD-PowerShell
Import-Module ActiveDirectory
}
Else
{
Install-RSATTools
Import-Module ActiveDirectory
}
}
choco upgrade serviceassistant --source https://www.myget.org/F/serviceassistant/api/v2 -y
choco upgrade sharepointconsole --source https://www.myget.org/F/sharepointconsole/api/v2 -y
Import-Module "$env:ProgramFiles\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell" -Force
$secstt = ConvertTo-SecureString "stuff" -asplaintext -force
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList "stuff"
Login-AzureRmAccount -Credential $creds
$clientid = $null
$clientsecret = $null
$passphrase = $null
$privatekey = $null
$publickeyid = $null
$enterpriseid = $null
$clientid2 = $null
$clientsecret2 = $null
$passphrase2 = $null
$privatekey2 = $null
$publickeyid2 = $null
$enterpriseid2 = $null
$secrets = Get-AzureKeyVaultSecret -VaultName boxauth
Foreach ($item in $secrets)
{
$azkey = Get-AzureKeyVaultSecret -name $item.Name -VaultName $item.VaultName
If ($azkey.Name -like "clientID")
{
$clientid = $azkey.SecretValueText
}
ElseIf ($azkey.Name -like "clientSecret")
{
$clientsecret = $azkey.SecretValueText
}
Elseif ($azkey.Name -like "passphrase")
{
$passphrase = $azkey.SecretValueText
}
ElseIf ($azkey.Name -like "privateKey")
{
$privatekey = $azkey.SecretValueText #.replace("\n","`n").ToString()
}
Elseif ($azkey.Name -like "publicKeyID")
{
$publickeyid = $azkey.SecretValueText
}
Elseif ($azkey.Name -like "enterpriseID")
{
$enterpriseid = $azkey.SecretValueText
}
If ($azkey.Name -like "clientID2")
{
$clientid2 = $azkey.SecretValueText
}
ElseIf ($azkey.Name -like "clientSecret2")
{
$clientsecret2 = $azkey.SecretValueText
}
Elseif ($azkey.Name -like "passphrase2")
{
$passphrase2 = $azkey.SecretValueText
}
ElseIf ($azkey.Name -like "privateKey2")
{
$privatekey2 = $azkey.SecretValueText #.replace("\n","`n").ToString()
}
Elseif ($azkey.Name -like "publicKeyID2")
{
$publickeyid2 = $azkey.SecretValueText
}
Elseif ($azkey.Name -like "enterpriseID2")
{
$enterpriseid2 = $azkey.SecretValueText
}
Else
{
}
}
$boxconfig = New-Object -TypeName Box.V2.Config.Boxconfig($clientid, $clientSecret, $enterpriseID, $privateKey, $passphrase, $publicKeyID)
$boxJWT = New-Object -TypeName Box.V2.JWTAuth.BoxJWTAuth($boxconfig)
$boxjwt
$tokenreal = $boxJWT.AdminToken()
$adminclient = $boxjwt.AdminClient($tokenreal, "401268528")
$adminclient
$boxconfig2 = New-Object -TypeName Box.V2.Config.Boxconfig($clientid2, $clientSecret2, $enterpriseID2, $privateKey2, $passphrase2, $publicKeyID2)
$boxJWT2 = New-Object -TypeName Box.V2.JWTAuth.BoxJWTAuth($boxconfig2)
$boxjwt2
$tokenreal2 = $boxJWT2.AdminToken()
$adminclient2 = $boxjwt2.AdminClient($tokenreal2, "401268528")
$adminclient2
$number = $adminclient.UsersManager.GetEnterpriseUsersAsync($null, 0, 1000)
$number.Wait()
$number.Result.TotalCount
} -CompletedScript {
param ($job)
$results = Receive-Job -Job $job | Select-Object -Last 1
If ($results -is [int])
{
$labelaccount.Text = "$results of 2250 licenses used"
If (2250 - [Int]$results -lt 10)
{
$labelaccount.ForeColor = 'Red'
}
Else
{
$labelaccount.ForeColor = 'Black'
}
}
Import-Module DepartModule -Force
$progressbaroverlay1.Visible = $false
$labelaccount.Visible = $true
$textbox1.Enabled = $true
$textbox2.Enabled = $true
$listview1.Enabled = $true
$button1.Enabled = $true
$buttonSearch.Enabled = $false
$buttonAssignLicense.Enabled = $false
$buttonRemoveBoxLicense.Enabled = $false
} -ArgumentList $ScriptDirectory, $scriptname
}