dsmod cmdlet & LOADSTATE not working togeather

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

dsmod cmdlet & LOADSTATE not working togeather

Post by tirwin@iot.in.gov » Wed Jul 27, 2016 6:23 pm

Below I have a form for PC Refresh you select a Old Backed up Computer from a drop down list (Left Side). The New Computer is the Computer your logged on to (Right Side). The tech fills in the data for the new computer and Submits the form (Button Not Shown). The AD attributes are updated and a LOADSTATE is run restoring the New Computer. I also want to disable the old computer. The problem is only 1 line of these two lines of code executes. I can comment out the LOADSTATE code and the computer is disabled in AD. I can comment out the dsmod code and the LOADSTATE will execute. When both are uncommented the second line of code does not execute? (Please see UI and Code on Submit_Click).
UI.PNG
UI.PNG (14.1 KiB) Viewed 1503 times
  1. $btnSubmitRestore_Click = {
  2.  
  3.    
  4.  
  5.     $global:oldComputerName = $comboboxComputerRestore.Text
  6.  
  7.     $global:oldDistinguishedName = Get-dn computer cn $global:oldComputerName
  8.  
  9.     $global:oldComputerObject = Get-ADObject ($global:oldDistinguishedName)
  10.  
  11.    
  12.  
  13.     $oldOrganizationalUnit = Get-ADObject "OU=Agencies, DC=state, DC=in, DC=us"
  14.  
  15.    
  16.  
  17.     $companyComputer = $comboboxNewOU.Text
  18.  
  19.     $newOrganizationalUnit = (Get-Dnldap state.in.us organizationalunit ou $companyComputer)
  20.  
  21.     $organizationalUnit = Get-ADObject ($newOrganizationalUnit)
  22.  
  23.    
  24.  
  25.     $departmentNumber = $txtNewComputerBillingCode.Text
  26.  
  27.     $accountType = $comboboxNewAccountType.Text
  28.  
  29.     $company = $comboboxNewIOTAsset.Text
  30.  
  31.    
  32.  
  33.     if ($accountType -eq "Seat")
  34.  
  35.     {
  36.  
  37.         $accountType = " "
  38.  
  39.     }
  40.  
  41.    
  42.  
  43.     if ($isAsset -eq "No")
  44.  
  45.     {
  46.  
  47.         $isAsset = " "
  48.  
  49.     }
  50.  
  51.     else
  52.  
  53.     {
  54.  
  55.         $isAsset = "IOT"
  56.  
  57.     }
  58.  
  59.    
  60.  
  61.     $global:oldComputerObject.departmentNumber = 'PCR'
  62.  
  63.     $global:oldComputerObject.extensionAttribute15 = ' '
  64.  
  65.     $global:oldComputerObject.company = 'DELETEME'
  66.  
  67.    
  68.  
  69.     $global:newComputerObject.departmentNumber = $departmentNumber
  70.  
  71.     $global:newComputerObject.extensionAttribute15 = $accountType
  72.  
  73.     $global:newComputerObject.company = $isAsset
  74.  
  75.    
  76.  
  77.     try
  78.  
  79.     {      
  80.  
  81.             $progressbaroverlay2.Visible = $true
  82.  
  83.             $progressbaroverlay2.Maximum = 80
  84.  
  85.             $progressbaroverlay2.Step = 10
  86.  
  87.             $progressbaroverlay2.Value = 10
  88.  
  89.        
  90.  
  91.         $global:oldComputerObject.SetInfo()
  92.  
  93.        
  94.  
  95.             $progressbaroverlay2.PerformStep()
  96.  
  97.             $progressbaroverlay2.PerformStep()
  98.  
  99.        
  100.  
  101.         $global:newComputerObject.SetInfo()
  102.  
  103.        
  104.  
  105.         Start-Sleep -s dsmod_only_
  106.  
  107.        
  108.  
  109.             $progressbaroverlay2.PerformStep()
  110.  
  111.             $progressbaroverlay2.PerformStep()
  112.  
  113.             $progressbaroverlay2.PerformStep()
  114.  
  115.        
  116.  
  117.         $global:newComputerObject.MoveTo($organizationalUnit)
  118.  
  119.        
  120.  
  121.             $progressbaroverlay2.PerformStep()
  122.  
  123.             $progressbaroverlay2.PerformStep()
  124.  
  125.             $progressbaroverlay2.PerformStep()
  126.  
  127.             $progressbaroverlay2.PerformStep()
  128.  
  129.             $progressbaroverlay2.PerformStep()
  130.  
  131.        
  132.  
  133.         $progressbaroverlay2.Visible = $false
  134.  
  135. #              "ALL CODE ABOVE WORKS"
  136.  
  137.  
  138.  
  139. #              "PROBLEM BELOW HERE"
  140.  
  141. #              $D = dsmod computer $global:oldDistinguishedName -disabled yes -c
  142.  
  143.  
  144.  
  145. #              $A = Start-Process -FilePath \\iotsdsp01pw\installs$\USMTWin10\dependencies\RUN-LOADSTATE.bat \\iotisip01pa.state.**.us\USMTBackups$\$global:oldComputerName -wait -PassThru;
  146.  
  147.  
  148.  
  149.  
  150.  
  151.         $A = Start-Process -FilePath \\iotsdsp01pw\installs$\USMTWin10\dependencies\RUN-LOADSTATE.bat \\iotisip01pa.state.**.us\USMTBackups$\$global:oldComputerName -wait -PassThru;
  152.  
  153.        
  154.  
  155.         $D = dsmod computer $global:oldDistinguishedName -disabled yes -c
  156.  
  157. #              "PROBLEM ABOVE HERE"
  158.  
  159.  
  160.  
  161.        
  162.  
  163.         $RestoreContinuedNetworkForm.Close()
  164.  
  165.     }
  166.  
  167.    
  168.  
  169.     catch
  170.  
  171.     {
  172.  
  173.         $labelDialogRedRestore.Text = "AD computer object not found"
  174.  
  175.     }
  176.  
  177.    
  178.  
  179. }

My question is do you see any obvious problem with the code which would cause this. I am using dsmod because RSTAT Tools are not installed on these computers (would be easier if it were). this .exe is run from a server share.

Any help would be greatly appreciated. :(

jvierra
Posts: 13939
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: dsmod cmdlet & LOADSTATE not working togeather

Post by jvierra » Wed Jul 27, 2016 7:50 pm

Asynchronous behavior.

The commands do not wait when executed from a form.

I recommend make this work without any reporting in a simple scrip executed from a PowerShell CLI script.
When you get this working add it to a job and then report on job progress.

User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

Re: dsmod cmdlet & LOADSTATE not working togeather

Post by tirwin@iot.in.gov » Thu Jul 28, 2016 9:41 am

Thanks for that. I just figured it out. Our PC Refresh team removed the C:\Windows\System32\dsmod.exe file from their IMAGE. Therefore it was not working on the newly re-imaged computers (it had been working). My development computer had that system file so it worked but it has to have that file to work. Sorry for the inconvenience. Thanks for your prompt response. Below is the code I used to return the GUI errors while the applicaiton was running. Found on your site from back in may of 2015. Thanks for the site.

try
{
$D = dsmod computer $global:oldDistinguishedName -disabled yes -c -ErrorAction $myError
}
catch {
[System.Windows.Forms.MessageBox]::Show("An error occurred performing $myError")
}

Locked