Question concerning "creating responsive forms post"
Posted: Sat Jan 13, 2018 6:17 am
Hello. I am trying to write a script that uses the "responsive form framework" that was posted at link below:
https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
I am having a bit of time trying to retrieve an array variable which the background job populates while it is running. At first I tried declaring the array prior to the creation and execution of the background job, eg:
I would have thought this method would have worked since the declaration of the array variable took place before the background was created and executed, however, one of the process that the "Completescript" block performs is using the values stored in the array in conjunction with "add-listviewitem" to populate a listview, but whenever I would run the code, it would process successfully up until the point where I called "Add-listviewitem", at which point I would get an error basically indicating that the values I was passing to the function were "null". So I re-wrote the function to (as closely as I could) mimic the progress bar example that you provide in your download section:
But still, again and again, no matter what I have tried, the "add-listviewitem" function errors out stating that the values I am passing it are Null values. Any advice on what I am doing wrong?
https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
I am having a bit of time trying to retrieve an array variable which the background job populates while it is running. At first I tried declaring the array prior to the creation and execution of the background job, eg:
Code: Select all
$array = New-object system.collections.arraylist
Try
{
Add-JobTracker -Name ReloadList -JobScript {
# Code to process
$array
}`
-completedScript {
param ($job)
#do stuff with $array
}`
-UpdateScript {
param ($Job)
$results2 = Receive-Job -Job $Job | Select-Object -Last 1
}
}
Catch
{
Write-Debug $_
}
Code: Select all
Try
{
Add-JobTracker -Name ReloadList -JobScript {
Get-AzureRmSubscription | % {
If ($_.Name -like $combobox2.Text) { Set-AzureRmContext -Subscription $_.Id }
}
$resourcegr = Get-AzureRmResourceGroup
$nic1 = Get-AzureRmNetworkInterface
$currentvms = Get-azurermvm | Select-Object -property Name, ResourceGroupName, OSProfile, @{ name = 'VMSize'; expression = { $_.Hardwareprofile.VMsize } }, ProvisioningState
$pubip = New-Object System.Collections.ArrayList
Get-AzureRmPublicIpAddress | % { $pubip.Add($_) }
foreach ($vm in $currentvms)
{
$inip = $null
foreach ($ip in $pubip)
{
If ($ip.ResourceGroupName -like $vm.ResourceGroupName)
{
$inip = $ip.IpAddress
}
}
Foreach ($nic in $nic1)
{
If ($nic.ResourceGroupName -like $vm.ResourceGroupName)
{
$privip = $nic.IpConfigurationstext | ConvertFrom-Json
}
}
$os = $null
If ($vm.osprofile.LinuxConfiguration -eq $null)
{
$os = "Windows"
}
Else
{
$os = "linux"
}
$custobj = New-Object -TypeName PSObject
$custobj | Add-Member -MemberType NoteProperty -Name "VMName" -Value $vm.Name
$custobj | Add-Member -MemberType NoteProperty -Name "VMResourceGroup" -Value $vm.ResourceGroupName
$custobj | Add-Member -MemberType NoteProperty -Name "VMOS" -Value $os
$custobj | Add-Member -MemberType NoteProperty -Name "VMType" -Value $vm.Vmsize
$custobj | Add-Member -MemberType NoteProperty -Name "VMPublicIP" -Value $inip
$custobj | Add-Member -MemberType NoteProperty -Name "VMprivateIP" -Value $privip.privateipaddress
$custobj | Add-Member -MemberType NoteProperty -Name "VMStatus" -Value $vm.ProvisioningState
$vmarray.Add($custobj)
}
$vmarray
}`
-CompletedScript {
param ($Job)
$progressbaroverlay1.Visible = $false
$results = Receive-Job -Job $job | Select-object -last 1
foreach ($ob in $results)
{
Add-ListViewItem -ListView $listview1 -Items $ob.VMName -SubItems $ob.VMResourceGroup, $ob.VMOS, $ob.VMType, $ob.VMPublicIP, $ob.VMprivateIP, $ob.VMStatus
}
$listview1.Refresh()
$combobox1.Enabled = $true
$textbox1.Enabled = $true
}`
-UpdateScript {
param ($Job)
$results2 = Receive-Job -Job $Job | Select-Object -Last 1
}
}
Catch [Exception]
{
Write-Debug $_
}