dsmod cmdlet & LOADSTATE not working togeather

Ask your 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.
This topic is 7 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

dsmod cmdlet & LOADSTATE not working togeather

Post by tirwin@iot.in.gov »

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 2352 times
  1. $btnSubmitRestore_Click = {
  2.    
  3.     $global:oldComputerName = $comboboxComputerRestore.Text
  4.     $global:oldDistinguishedName = Get-dn computer cn $global:oldComputerName
  5.     $global:oldComputerObject = Get-ADObject ($global:oldDistinguishedName)
  6.    
  7.     $oldOrganizationalUnit = Get-ADObject "OU=Agencies, DC=state, DC=in, DC=us"
  8.    
  9.     $companyComputer = $comboboxNewOU.Text
  10.     $newOrganizationalUnit = (Get-Dnldap state.in.us organizationalunit ou $companyComputer)
  11.     $organizationalUnit = Get-ADObject ($newOrganizationalUnit)
  12.    
  13.     $departmentNumber = $txtNewComputerBillingCode.Text
  14.     $accountType = $comboboxNewAccountType.Text
  15.     $company = $comboboxNewIOTAsset.Text
  16.    
  17.     if ($accountType -eq "Seat")
  18.     {
  19.         $accountType = " "
  20.     }
  21.    
  22.     if ($isAsset -eq "No")
  23.     {
  24.         $isAsset = " "
  25.     }
  26.     else
  27.     {
  28.         $isAsset = "IOT"
  29.     }
  30.    
  31.     $global:oldComputerObject.departmentNumber = 'PCR'
  32.     $global:oldComputerObject.extensionAttribute15 = ' '
  33.     $global:oldComputerObject.company = 'DELETEME'
  34.    
  35.     $global:newComputerObject.departmentNumber = $departmentNumber
  36.     $global:newComputerObject.extensionAttribute15 = $accountType
  37.     $global:newComputerObject.company = $isAsset
  38.    
  39.     try
  40.     {      
  41.             $progressbaroverlay2.Visible = $true
  42.             $progressbaroverlay2.Maximum = 80
  43.             $progressbaroverlay2.Step = 10
  44.             $progressbaroverlay2.Value = 10
  45.        
  46.         $global:oldComputerObject.SetInfo()
  47.        
  48.             $progressbaroverlay2.PerformStep()
  49.             $progressbaroverlay2.PerformStep()
  50.        
  51.         $global:newComputerObject.SetInfo()
  52.        
  53.         Start-Sleep -s dsmod_only_
  54.        
  55.             $progressbaroverlay2.PerformStep()
  56.             $progressbaroverlay2.PerformStep()
  57.             $progressbaroverlay2.PerformStep()
  58.        
  59.         $global:newComputerObject.MoveTo($organizationalUnit)
  60.        
  61.             $progressbaroverlay2.PerformStep()
  62.             $progressbaroverlay2.PerformStep()
  63.             $progressbaroverlay2.PerformStep()
  64.             $progressbaroverlay2.PerformStep()
  65.             $progressbaroverlay2.PerformStep()
  66.        
  67.         $progressbaroverlay2.Visible = $false
  68. #              "ALL CODE ABOVE WORKS"
  69.  
  70. #              "PROBLEM BELOW HERE"
  71. #              $D = dsmod computer $global:oldDistinguishedName -disabled yes -c
  72.  
  73. #              $A = Start-Process -FilePath \\iotsdsp01pw\installs$\USMTWin10\dependencies\RUN-LOADSTATE.bat \\iotisip01pa.state.**.us\USMTBackups$\$global:oldComputerName -wait -PassThru;
  74.  
  75.  
  76.         $A = Start-Process -FilePath \\iotsdsp01pw\installs$\USMTWin10\dependencies\RUN-LOADSTATE.bat \\iotisip01pa.state.**.us\USMTBackups$\$global:oldComputerName -wait -PassThru;
  77.        
  78.         $D = dsmod computer $global:oldDistinguishedName -disabled yes -c
  79. #              "PROBLEM ABOVE HERE"
  80.  
  81.        
  82.         $RestoreContinuedNetworkForm.Close()
  83.     }
  84.    
  85.     catch
  86.     {
  87.         $labelDialogRedRestore.Text = "AD computer object not found"
  88.     }
  89.    
  90. }

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: dsmod cmdlet & LOADSTATE not working togeather

Post by jvierra »

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
Last visit: Tue Mar 14, 2017 9:54 am

Re: dsmod cmdlet & LOADSTATE not working togeather

Post by tirwin@iot.in.gov »

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")
}
This topic is 7 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked