
VeeDub
Active Members-
Posts
259 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
VeeDub's Achievements
-
VeeDub reacted to a post in a topic: Need help adding to a 2D array
-
VeeDub reacted to a post in a topic: Need help adding to a 2D array
-
@SmOke_N The example I was following doesn't use any extra parameters ; Add item delimited string $aArray = $aArray_Base $sFill = "New Item 2 - 0|New Item 2 - 1" _ArrayAdd($aArray, $sFill) _ArrayDisplay($aArray, "2D - Item delimited") However, I have also tried to implement your suggestion #include <Array.au3> Global $FILE_Summary[500][1] $Timestamp_YYYY_MM = "2022-04" ; Search Array for YYYY-MM $iIndex = _ArraySearch($FILE_Summary,$Timestamp_YYYY_MM) If $iIndex = -1 Then ; Not found - add entry Local $sFill = $Timestamp_YYYY_MM & "|1" ConsoleWrite("sFill: " & $sFill & @CRLF) $Status = _ArrayAdd($FILE_Summary,$sFill,0) ConsoleWrite("Status: " & $Status & @CRLF) ConsoleWrite("@error: " & @error & @CRLF) EndIf _ArrayDisplay($FILE_Summary) sFill: 2022-04|1 Status: -1 @error: 3 I'm now specifying column: 0 I don't believe that I need to specify Delim_Row. Maybe I really do - and that's the issue. However my thinking is that I'm adding a row with 2 columns: 2022-04 | 1
-
Hello, I'm trying to write code to add to a 2D array. I've tried to use the examples in the help as a template, but I'm doing something wrong which I can't see. What I'm trying to do is use an array to summarise the contents of a folder with a large number of files which I want to summarise by YYYY-MM So, if there are 100,000 files. I want to summarise those files by there timestamp. So, for each file: I will determine it's timestamp (YYYY-MM) Then I will lookup that timestamp in the array If the timestamp exists, I will add 1 to the counter If the timestamp does not exist in the array, I will add an entry with a count of 1 The code that I'm using to add an entry to the array doesn't work. #include <Array.au3> Global $FILE_Summary[500][1] $Timestamp_YYYY_MM = "2022-04" ; Search Array for YYYY-MM $iIndex = _ArraySearch($FILE_Summary,$Timestamp_YYYY_MM) If $iIndex = -1 Then ; Not found - add entry Local $sFill = $Timestamp_YYYY_MM & "|1" ConsoleWrite("sFill: " & $sFill & @CRLF) $Status = _ArrayAdd($FILE_Summary,$sFill) ConsoleWrite("Status: " & $Status & @CRLF) ConsoleWrite("@error: " & @error & @CRLF) EndIf _ArrayDisplay($FILE_Summary) sFill: 2022-04|1 Status: -1 @error: 3 error:3 = $vValue has too many columns to fit into $aArray Clearly there is a problem, but to me $sFill looks to be correct, so I need a fresh perspective. Thanks VW
-
argumentum reacted to a post in a topic: Intermittent problem running Powershell scripts
-
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
Using a bat file to call the Powershell script rather than a cmd file ended up being the resolution here. That being said, if I were doing this again from scratch I would have a close look at @argumentum post here I'm a fan of this approach. However, in this instance as I already had the code "working" apart from intermittent glitches, just changing to using a bat file instead of a cmd file was easier. -
VeeDub reacted to a post in a topic: Intermittent problem running Powershell scripts
-
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
I don't know yet whether using bat files to call the Powershell scripts is going to be more reliable (and ultimately that will be what matters). But one advantage of using bat files is that the bat files play very nicely with the logging in _RunWaitEx 2024-01-31 Wed 22:04 @error: 0 2024-01-31 Wed 22:04 Exitcode: 0 2024-01-31 Wed 22:04 Exitcode: 0 2024-01-31 Wed 22:04 Output: C:\Users\AMR\AppData\Local\Temp\2>powershell -ExecutionPolicy Bypass -File C:\ZEN\ALR\Check_if_VM_Exists.ps1 A VM named: ALR_CyberX_DR3-4 already exists All of the bat files provide useful Output -
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
I've done some Google searching on issues with calling Powershell scripts and there are others that have had issues. One work-around that somebody reported as being effective, was calling the Powershell script via a batch file. That is not hard for me to test, so I am trying that in the meantime. -
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
Because perhaps I'm not going to be able to call Powershell directly in AutoIt, which would be my preference. I'm exploring a few other options. This transcript option is useless, it doesn't log anything that is relevant. -
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
The problem that I have is that all the examples are hardcoded, that is, the example code is "fixed". Whereas all my powershell snippets / functions are designed to work on a VM and the VM is a variable. So, I don't see how I can use the examples that you posted, unless I was to write 5 individual versions (for the 5 VM's that I'm automating now. But that approach is not desirable as the VM's will change in the future. So, what I would want to do is build a command string - where I can alter the powershell commands dynamically (i.e. change the VM that is being referenced). But I have tried doing that, and while the argument looks fine to me. It is not being accepted. This is what I mean Local $sRet $Command1 = "'" & "powershell " $Command2 = """" & "Get-VM -name " $Command3 = $ALR_Host_VM & """" & "'" $Command = $Command1 & $Command2 & $Command3 ConsoleWrite("Command: " & $Command & @CRLF) $sRet = _RunWaitEx($Command) ConsoleWrite("$sRet: " & $sRet & @CRLF) Command: 'powershell "Get-VM -name ALR_CyberX_DR3-4"' $sRet: ''powershell' is not recognized as an internal or external command, operable program or batch file. But if I do a hard-coded argument, the call works. Local $sRet #cs $Command1 = "'" & "powershell " $Command2 = """" & "Get-VM -name " $Command3 = $ALR_Host_VM & """" & "'" $Command = $Command1 & $Command2 & $Command3 ConsoleWrite("Command: " & $Command & @CRLF) #ce $sRet = _RunWaitEx('powershell "Get-VM -name ALR_CyberX_DR3-4"') ConsoleWrite("$sRet: " & $sRet & @CRLF) $sRet: Name State CPUUsage(%) MemoryAssigned(M) Uptime Status Version ---- ----- ----------- ----------------- ------ ------ ------- ALR_CyberX_DR3-4 Running 0 4096 01:32:18.8370000 Operating normally 9.0 The arguments looks identical to me in the two calls. Powershell is a PITA -
VeeDub reacted to a post in a topic: Intermittent problem running Powershell scripts
-
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
I'm having some trouble converting a Powershell script to _RunWaitEx syntax Here is an example $VMName = "ALR_3-4" $VM = Get-VM -name $VMName -ErrorAction SilentlyContinue if (!$VM) { Write-Host "No VM named: $VMName exists" "No VM named: $VMName exists" | Out-File -FilePath C:\ZEN\ALR\VM_Not_Found.txt} else { Write-Host "A VM named: $VMName already exists" "A VM named: $VMName already exists" | Out-File -FilePath C:\ZEN\ALR\VM_Exists.txt} I think I will need to build a command string and then pass that to _RunWaitEx Local $Command = 'powershell "$VMName = " & $ALR_Host_VM & Local $sRet = _RunWaitEx($Command) But I'm not sure how to convert the multi-line powershell script arguments to a _RunWaitEx call -
argumentum reacted to a post in a topic: Intermittent problem running Powershell scripts
-
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
I think I will try your suggestion instead. If nothing else I will be able to query the return code if the behaviour continues. Thanks! -
VeeDub reacted to a post in a topic: Intermittent problem running Powershell scripts
-
argumentum reacted to a post in a topic: Intermittent problem running Powershell scripts
-
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
I have found this Start-Transcript -Path "Drive:\Folder\Transcript.txt" ## YOUR EXISTING CODE ## Stop Transcript Am going to try it. -
argumentum reacted to a post in a topic: Intermittent problem running Powershell scripts
-
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
Unfortunately the issue still exists. Ran the AutoIt program yesterday, 5 VM's were managed, so that means there were 15 Powershell script operations and all completed correctly. Ran the AutoIt program today, and on the 5th VM, the second Powershell script did not update correctly. The second Powershell script is supposed to update the VM boot device. In this instance this didn't happen. I call this Powershell script 5 times, because since I've become aware of this issue, I'm trying to work out a way to ensure that the script actions are performed. So the script was called 5 times, but didn't update the boot device. No errors were reported. 2024-01-31 Wed 11:12 Set VM boot device to DVD 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: 2024-01-31 Wed 11:12 @error: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Exitcode: 0 2024-01-31 Wed 11:12 Output: The logging above is identical to the logged entries when the boot device has been successfully updated for earlier VM's. -
argumentum reacted to a post in a topic: Intermittent problem running Powershell scripts
-
VeeDub reacted to a post in a topic: Intermittent problem running Powershell scripts
-
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
@argumentum Thanks for sharing. I have replaced my function with _RunWaitEx I've watched the first calls to the function and the powershell is executing as it should. Which is not unlike my function most of the time. Hopefully _RunWaitEx just works. But if we get the same behaviour that I've been observing some of the time, I've also added some logging for: UpdateEventLog("@error: " & @error) UpdateEventLog("Exitcode: " & @extended) UpdateEventLog("Exitcode: " & $iExitCode) UpdateEventLog("Output: " & $sOutput) Which will hopefully give me some idea what is going on. -
Intermittent problem running Powershell scripts
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
One option I've thought of, is there a way that I can log Powershell output when a script is executed? Presumably when the scripts are not executing as expected, some error condition has arisen and hopefully some error message is being generated. If I can capture that, then I'll have some insight as to what is going on. -
Hello, I have an AutoIt script that automates tasks with Hyper-V VMs. Some of these tasks, like turning on and turning off the VM are performed using Powershell, which I'm calling from within AutoIt. Here is a Powershell script: Turn_on_VM.ps1 $VMName = "ALR_testclient3" Start-VM -VMName $VMName Here is how I call the Powershell script runPowershellScript('C:\ZEN\ALR\Turn_On_VM.ps1') Func runPowershellScript($sScript) RunWait("powershell.exe -ExecutionPolicy Bypass -File " & $sScript, "", @SW_HIDE) EndFunc I run the AutoIt script daily and what I'm finding is that 4 - 5 days per week, the script works fine. Then on the "off days", the Powershell scripts are clearly not executing as expected. The AutoIt script is running on Windows Server 2019. The script is compiled as x64. I am specifying: #RequireAdmin After suggestions on thing to try to make the AutoIt script robust. Is there another way to execute the Powershell scripts? Thanks VW
-
Question about using _ImageSearch_Area
VeeDub replied to VeeDub's topic in AutoIt General Help and Support
The example is using _ImageSearch rather than _ImageSearch_Area and it does work. Either there is a problem with _ImageSearch_Area or I'm not calling it correctly. Either way it looks like I can use _ImageSearch to complete the task.