2016-09-26 4 views
0

양식을 만들고 동적으로 CheckBox 및 CheckBox 이름을 추가했습니다. Get-LicenseDetails 함수에서 특정 CheckBox를 프로그래밍 방식으로 검사하려면 어떻게해야합니까? 누락 된 대괄호가 추가되었습니다.함수에서 CheckBoxes에 액세스하는 방법

import-module MSOnline 

Function Get-LicenseDetails { 
    Param ($upn) 
    $licenses = Get-MsolUser -UserPrincipalName $upn 
    ForEach ($license in $licenses.Licenses) { 
     If ($license.AccountSkuId -like '*ENTERPRISEPACK') { 
      $serviceName = $serviceStatus.ServicePlan.ServiceName 
      $checkBox.Checked = $true 
     } 
    } 
} 

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$System_Drawing_Point = New-Object System.Drawing.Point 
Add-Type -AssemblyName System.Windows.Forms 
$form = New-Object Windows.Forms.Form 
$form.Text = "Office 365 Licensing" 
$form.Name = "Form1" 
$form.Size = New-Object Drawing.Size @(316, 510) 

#SEARCH BUTTON 
$searchBtn = New-Object System.Windows.Forms.Button 
$System_Drawing_Point.X = 226 
$System_Drawing_Point.Y = 38 
$searchBtn.Location = $System_Drawing_Point 
$searchBtn.add_click({Get-LicenseDetails "[email protected]"}) 
$searchBtn.Size = New-Object System.Drawing.Size(67, 23) 
$searchBtn.Text = "Click Me" 
$form.Controls.Add($searchBtn) 

#CHECKBOXES 
$y = 80 
$Services = (Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq "ENTERPRISEPACK"}).ServiceStatus.ServicePlan.ServiceName 
ForEach ($service in $Services) { 
    $checkbox = New-Object System.Windows.Forms.CheckBox 
    $checkbox.Text = $service 
    $checkbox.Name = "CheckBox_$service" 
    $checkbox.Size = New-Object System.Drawing.Size(260,17) 
    $checkbox.Location = New-Object System.Drawing.Size(10,$y) 
    $y += 25 
    $form.Controls.Add($checkbox) 
} 

$drc = $form.ShowDialog() 

답변

0

우선, System.Drawing 어셈블리를로드 할 대괄호가 없습니다.

Get-LicenseDetails에있는 CheckBox에 액세스하여 기능에 전달하거나 $global:을 사용하여 액세스 할 수 있습니다. 그러나 GUI 요소를 해당 함수에 전달하지는 않습니다. 대신 모델 (새 객체)을 만들고 Get-LicenseDetails 메서드로 전달합니다.

0

좋아, 알아 냈어. 함수에서 다음 줄을 사용했습니다.

$checkBoxName = "CheckBox_" + $serviceName 
$checkbox = $form.Controls | Where-Object {$_.name -eq $checkBoxName} 
$checkbox.Checked = $true 
관련 문제