所以我正在使用那种有问题的 Sapien powershell studio 来制作一个 powershell 驱动的 GUI 应用程序,并且我正在尝试执行 ADSI 查询。
$nameOfDeviceInput 是一个 System.Windows.Forms.TextBox
在一种形式上,我具有以下功能:
$buttonPerformAction_Click={
if (FindInAD($nameOfDeviceInput.Text).Count -gt 0)
{
$buttonPerformAction.BackColor = 'Red'
$buttonPerformAction.Text = "System already exists in AD with that name. Try another name"
return
}
.....
}
在“主”表单上,我有 FindInAD 函数
function FindInAd($nameOfSystem)
{
Write-Host "seeking system" $nameOfSystem
([adsisearcher]"(CN=$nameOfSystem)").FindAll()
}
FindInAd() 失败,因为无论出于何种原因,$nameOfSystem 设置为 1,如果我没有将其显式转换为字符串,它会隐式转换为 Int32(显然)
我尝试了以下方法:
通过标注它所属的表单来完全限定文本框输入( $adObjectModifier )
$buttonPerformAction_Click={
if (FindInAD($adObjectModifier.$nameOfDeviceInput.Text).Count -gt 0)
{
$buttonPerformAction.BackColor = 'Red'
$buttonPerformAction.Text = "System already exists in AD with that name. Try another name"
return
}
.....
}
将 $nameOfSystem 参数显式转换为 [string] 类型
function FindInAd([string]$nameOfSystem)
{
Write-Host "seeking system" $nameOfSystem
([adsisearcher]"(CN=$nameOfSystem)").FindAll()
}
将原始字符串从 AdObjectModifier 表单传递到 FindInAD。
....
if (FindInAD("Test").Count -gt 0)
....
当时输出管道上没有其他东西,(至少不是来自我)在方法调用之间。它是 EventHandler > 带有字符串参数的函数调用
为什么我传递的字符串变成了数字???
编辑:我认为我传递的参数正在以某种方式自动替换为结果布尔值,但这对我来说没有任何意义......