powershell - Application runs in Windows 7 but not in Windows 10 -


i have created app , restore of computers. allows modification of adobjects through use of custom profile.ps1 file. app runs fine in ise no errors , works no errors in windows 7. however, when try run in newly imaged windows 10 machine "property can not found" errors on object properties.

the thing can read properties when fill comboboxes fine. error occurs when form submitted. attach 1 of forms having problem with. again runs fine in windows 7, not windows 10.

could problem microsoft updates?

also, yes, setting set-executionpolicy -scope process -executionpolicy unrestricted.

error message:

the property 'company' cannot found on object. verify property exist , can set. + $co.company = $company + categoryinfo :invalidoperation: (:) [] runtimeexeption

code:

. \\iotsdsp01pw\installs$\movetoou\pcdeployment\profile.ps1  #region validation functions function validate-isemail ([string]$email) {   return $email -match "^(?("")("".+?""@)|(([0-9a-za-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-za-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-za-z][-\w]*[0-9a-za-z]\.)+[a-za-z]{2,6}))$" }  function validate-isurl ([string]$url) {   if ($url -eq $null) {     return $false   }    return $url -match "^(ht|f)tp(s?)\:\/\/[0-9a-za-z]([-.\w]*[0-9a-za-z])*(:(0-9)*)*(\/?)([a-za-z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$" }  function validate-isname ([string]$name, [int]$maxlength) {   if ($maxlength -eq $null -or $maxlength -le 0) {     #set default length 40     $maxlength = 40   }    return $name -match "^[a-za-z''-'\s]{1,$maxlength}$" }  function validate-isip ([string]$ip) {   return $ip -match "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" }  function validate-isemptytrim ([string]$text) {   if ($text -eq $null -or $text.trim().length -eq 0) {     return $true   }    return $false }  function validate-isempty ([string]$text) {   return [string]::isnullorempty($text) }  function validate-isdate ([string]$date) {   return [datetime]::tryparse($date, [ref](new-object system.datetime)) } #endregion  $no_load = {   $newform.close()   #initialize variables   $datetime = get-date -format g   $username = (get-wmiobject -class win32_computersystem -property username).username   $computername = $env:computername    #varables display   $distinguishedname = (get-dn computer cn $computername)   $computerobject = (get-adobject $distinguishedname)   $organizationalunit = (get-adobject "ou=agencies, dc=state, dc=in, dc=us")    #initialize form controls   $lblusernamenewno.text = $username   $lblcomputernamenewno.text = $computername   $lblphysicallocationnewno.text = $computerobject.location   $txtbillingcodenewno.text = $computerobject.departmentnumber   $comboboxaccounttypenewno.text = $computerobject.extensionattribute15   $comboboxorganizationalunitnewno.text = $computerobject.company   load-combobox -combobox $comboboxorganizationalunitnewno ($organizationalunit.children | %{ $_.ou }) }  #region control helper functions function load-combobox {   param (     [validatenotnull()]     [parameter(mandatory = $true)]     [system.windows.forms.combobox]$combobox,     [validatenotnull()]     [parameter(mandatory = $true)]     $items,     [parameter(mandatory = $false)]     [string]$displaymember,     [switch]$append   )    if (-not $append) {     $combobox.items.clear()   }    if ($items -is [object[]]) {     $combobox.items.addrange($items)   } elseif ($items -is [array]) {     $combobox.beginupdate()     foreach ($obj in $items) {       $combobox.items.add($obj)     }     $combobox.endupdate()   } else {     $combobox.items.add($items)   }    $combobox.displaymember = $displaymember }  #validation function parametervalidate {   param (     [parameter(mandatory = $true)]     [validatenotnull()]     [validatelength(1, 10)]     [string]$text   )   return $true }  $comboboxorganizationalunitnewno_validating = [system.componentmodel.canceleventhandler]{   #check if name field empty   $result = validate-isemptytrim $comboboxorganizationalunitnewno.text   if ($result -eq $true) {     #mark failure if validation failed     $script:validationfailed = $true     #display error message     $errorprovider1.seterror($comboboxorganizationalunitnewno, "please select agency.");   } else {     #clear error message     $errorprovider1.seterror($comboboxorganizationalunitnewno, "");   } }  $txtbillingcodenewno_validating = [system.componentmodel.canceleventhandler]{   #check if name field empty   $result = validate-isemptytrim $txtbillingcodenewno.text   if ($result -eq $true) {     #mark failure if validation failed     $script:validationfailed = $true     #display error message     $errorprovider1.seterror($txtbillingcodenewno, "please enter billing code.");   } else {     #clear error message     $errorprovider1.seterror($txtbillingcodenewno, "");   } }  $comboboxaccounttypenewno_validating = [system.componentmodel.canceleventhandler]{   $result = validate-isemptytrim $comboboxaccounttypenewno.text   if ($result -eq $true) {     #mark failure if validation failed     $script:validationfailed = $true     #display error message     $errorprovider1.seterror($comboboxaccounttypenewno, "please enter agency type.");   } else {     #clear error message     $errorprovider1.seterror($comboboxaccounttypenewno, "");   } }  $control_validated = {   #pass calling control , clear error message   $errorprovider1.seterror($this, ""); }  $no_formclosing = [system.windows.forms.formclosingeventhandler]{   #event argument: $_ = [system.windows.forms.formclosingeventargs]   #validate on ok button   if ($no.dialogresult -eq "ok") {     #init validation failed variable     $script:validationfailed = $false     #validate child control , cancel if fail     $no.validatechildren()     #cancel if validation failed     $_.cancel = $script:validationfailed   } }  #events $buttoncolor_click = {   #todo: place custom script here   $colordialog1.showdialog() }  $linklblviewlistnewno_linkclicked = [system.windows.forms.linklabellinkclickedeventhandler]{   start-process "http://billingcodes.iot/" }  $btnsubmitnewno_click = {   #todo: place custom script here   $company = $comboboxorganizationalunitnewno.text   $departmentnumber = $txtbillingcodenewno.text   $accounttype = $comboboxaccounttypenewno.text    if ($accounttype -eq "seat") {     $accounttype = " "   }    #varables set-adobject   $computerobject.company = $company   $computerobject.departmentnumber = $departmentnumber   $computerobject.extensionattribute15 = $accounttype    try {     $computerobject.setinfo()     [environment]::exit(1)   } catch {     $labeldialogrednewno.text = "ad computer object not found"   } } 

this culprit (from can see):

$no_load = {   ...   $computerobject = (get-adobject $distinguishedname)   ... } ... $btnsubmitnewno_click = {   ...   $computerobject.company = $company   ... } 

you assign computer object variable $computerobject in 1 scriptblock, , try change 1 of properties in scriptblock. however, able share variable between scriptblocks need make global variable, otherwise have 2 separate local variables know nothing each other.

$no_load = {   ...   $global:computerobject = get-adobject $distinguishedname   ... } ... $btnsubmitnewno_click = {   ...   $global:computerobject.company = $company   ... } 

btw, doubt ever worked in windows 7, since failed same error on windows 7 test box.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -