Plotting with PowerShell on Windows

PowerShell Window

Windows PowerShell has developed into a great tool to manage and execute scripts on Windows machines. Its built into every install of Windows 10. In this post, we go into how to run plotters with PowerShell. There are a few advantages to running plotters in PowerShell:

  1. Plotting is not tied to the Chia GUI. If the Chia client experiences a crash or bug, your plotter will continue to work while the client recovers.
  2. Every PowerShell window is one plotter. If you plan to perform plotting in parallel (running multiple plotters on the same machine) then this is a perfect way to visibly see how many plotters are running and how far along they are.
  3. You can cancel a plotter queue after the current plot. Each plotter has its own queue length in PowerShell. Something that I discovered by accident, you can click the PowerShell window and press CTRL-C. Nothing will confirm the key command, but at the end of the current plot, the plotter will abort the queue.
  4. You can create a PowerShell script to run all your plotters. Possibly the best feature, you can run a script and all of your plotters are launched, with their own settings, in their own individual windows. Perfect.

There are a few house keeping rules first before using PowerShell so you don’t hit the pitfalls that I have. Perform these steps:

  1. Open Powershell by pressing the Windows key and typing “PowerShell”
  2. When the PS window opens, click the top left of the window to open a menu. In that menu, click “Properties.”
  3. In the new window, Uncheck the box that says “QuickEdit mode”. Normally this feature is great when you want to highlight text in the window and copy it out to another place. But, it has the bad side effect of pausing whatever is running in the window. This is bad if a plotter is plotting and you accidentally click the window while dragging it around. Disabling QuickEdit mode prevents this from happening. If you want to select text in the future, just right-click inside the PS window and select “Mark”.
  4. Next, click the “Layout” tab. Locate the “Height” field. This is how much scroll back you want. I like a ton of scroll back so I max this out at 9999. This is so that you can view the progress info of many plots to see times.
  5. Click the OK button once complete.
  6. If you ever plan executing your own PowerShell scripts, enter the command below in an Administrator PowerShell Window so that it is enabled:
set-executionpolicy remotesigned

Now that PowerShell is setup to prevent you from making my horrible mistake, we can proceed with how to get a plotter started. In your PS window, enter the following command:

cd "C:\Users\<username>\AppData\Local\chia-blockchain\app-1.0.5\resources\app.asar.unpacked\daemon\"

In the command above, note the two bolded locations. The “<username>” needs to be replaced with YOUR username on your machine. Next the “app-1.0.5” is going to be replaced with the version of chia that you are running. Currently the latest is 1.0.5. But it won’t be like this always.

After you Change Directories (cd) to that folder, enter the following command to begin a plotter:

.\chia.exe plots create -k 32 -b 3389 -u 128 -r 2 -t E:\temp -d D:\plot -n 1

There is a lot of information here so I’ll break it up:

  • .\chia.exe plots create – This is pretty self explanatory. I want chia to create a plot.
  • -k 32 – This is the size of plot you want to create. K=32 is the minimum size of a plot that is considered valid on the Chia Network. It is also the fastest to create. You can go smaller on the K value but those plots are not valid on the network.
  • -b 3389 – This is the amount of ram you want to allocate to the plotter. It does not use all this ram at once, its just the limit. But, windows will preallocate this amount and call it “committed” which might push other applications to virtual memory on disk if committed is maxed. 3389 is the perfect amount if you are using 2 threads. I have found that 4 threads requires a minimum of 3408; 6 threads 3416; 8 threads 3424.
  • -u 128 – This is the bucket size. Essentially its how many pieces you want the workload to be divided in. If you change this to 64, then you have to double the ram amount. From my experience, there is no change in plot speed messing with this number. So leave it at 128.
  • -r 2 – This is the number of threads you want for the plotter. The plotter works in four phases. This number only affects phase 1 of a plot. Phase 2, 3, and 4 are all single threaded. In my testing, I saw a 30 minute speed improvement from using 2 threads to 4 threads. Then, I only saw a 5 minute improvement from 4 threads to 6 threads. There is diminishing returns definitely. Always try to use at least 2 though, because 1 thread is really slow.
  • t E:\temp – This is your temporary directory. Remember to pick a fast drive here.
  • -d D:\plot – This is your final directory. This can be an external usb drive or another type of fat spinny hard drive.
  • -n 1 – Finally this is your queue. How many plots do you want to make with these settings? Remember, you can set any number here and then stop it with CTRL-C.
  • Since we are plotting on the same machine as the farmer, the keys needed to generate the plots are automatically brought in. So we don’t need to specify those here.

That’s pretty much it for the PowerShell command. Executing this command will start the plotter on its journey and it will print its progress in the window. Next is the scripting part. Below I have placed the script I use on my machine. Copy and paste this script into notepad and save the file as plotterscript.ps1, while selecting “All Files” for the file type:

Notepad “Save As..” Window

Here is the script. Copy/paste the invoke-expression line for each plotter you wish to start :

#Begin Script
############Plotters for Temp Drive###############
invoke-expression 'cmd /c start powershell -NoExit -Command {cd "C:\Users\<yourusername>\AppData\Local\chia-blockchain\app-1.0.5\resources\app.asar.unpacked\daemon\";$host.ui.RawUI.WindowTitle = "t1p1"; start-sleep 0 ; .\chia.exe plots create -k 32 -b 3389 -u 128 -r 2 -t E:\temp -d D:\plot -n 1 ;Read-Host -Prompt "press enter to exit"}'

Lets breakdown the script above. You will see semicolons in the script above. These separate each command of the new PowerShell window.

  • invoke-expression ‘cmd /c start powershell -NoExit – This first part is what tells PowerShell to open another PowerShell window. The -NoExit flag is to not close the window when complete. Just in case you want to review the results.
  • -Command {cd C:\Users\<yourusername>\AppData\Local\chia-blockchain\app-1.0.5\resources\app.asar.unpacked\daemon\ – The -Command here is the commands we want to pass to the new PowerShell window that opens up.
  • $host.ui.RawUI.WindowTitle = “t1p1” – This command allows you to rename the title of the PowerShell window. This is to keep track which window it is. Here, the name scheme I’m using is tempdrive 1, plotter 1. Since I have two plotter drives.
  • start-sleep 0 – This next command is critical. When running plots in parallel you need to space them out a bit so that all of them are not trying to write to the final directory at the same time. If using an external drive, this causes a major headache. The value here is in seconds. For example, if you want an hour between plotters, it would be 0 for the first plotter, 3600 for the second plotter, 7200 for the third, etc.
  • .\chia.exe plots create -k 32 -b 3389 -u 128 -r 2 -t E:\temp -d D:\plot -n 1 – This is the Chia plotter command that was explained above. Update this to your settings.
  • Read-Host -Prompt “press enter to exit” – This was a hold-me-over from a previous version of the script incase for some reason the “-NoExit flag didn’t work.

There you have it, this should provide you with enough information in order to create and tweak your own scripts in order to maximize your plotters on your machine without having to worry about Chia Client issues.

With the file saved, all you need to execute it is to right click the file and select “Run with PowerShell”.

29 thoughts on “Plotting with PowerShell on Windows

  1. Alex, may i take a little futher? Is it possible via PS parse when “Starting phase 2/4: Backpropagation into tmp files…” appears in the windows and only that kick next plot? It would be much precise than timing offset option.

    1. Yes, This is possible and would be more precise. But at that point, you are developing something more than a simple script. If you do this or find this somewhere, let me know.

  2. Hi Alex could you please explain the last part of the command — Read-Host -Prompt “press enter to exit”

    I just started my first round of plots (8 in parallel) using your script but about an hour in I hit something that stopped them all, and then the “press enter to exit” message was displayed.

    Any ideas on what I could have done?

    Thanks!

  3. Hi Alex, thank you for this great guide, just a quick question though, is there any simple way it can be changed so instead of waiting for a keypress after creating the plot it simply loops and does it again (I’m assuming this would allow it to then run until the target drive is full of plots).

    1. Hi James, I suppose there could be a way to loop this, but wouldn’t it be better to adjust the “-n” value? This way, it will keep plotting up to that number. And, if you ever need to stop it, press CTRL-C and it will stop after the current plot is done.

  4. This is great Alex! How would I add logging so that the output of the windows goes to individual log files? Easier to parse through for stats and timings information.

    1. Hi charpman, there are many ways to pipe output to log files. I haven’t looked that much into it, but if you come across a good method share it here and I can add it to the post.

  5. I use -redirectstandardoutput in order to pipe out the log.
    Example of a powershell command:

    start-process ./chia.exe -redirectstandardoutput C:\Temp\Chia.Logs\log.20210428.0927.log -argumentlist “plots create -k 32 -b 4000 -u 128 -r 4 -t E:\Temp -d D:\Plot -n 1”

    For now I start the plots manually, so “20210428.092700” is a manual timestamp.

  6. He Alex, thanks for the great post. I have a Powershell Newbie Question:
    So if I wanted to Powershell Plots in Parallels (let’s say 3 sets in Parallel), do I just make 3 copies of the code in one text file? Obviously change the naming and delay of each set, and separate each set by a space (enter key).

  7. Hello Alex, thank you for your guides!

    Could you please explain me the command “start-sleep”. So in my case, I copy-pasted your script and saved three files with different titles of course, so i stared first, waited an hour and started second one manually, waited an hour and started third script. What exactly the command “start-sleep” does in my case?

    1. Hi Max, The start-sleep is the actual wait command. So you don’t actually have to wait to launch the next one manually. Just launch them all at once and the wait is built in.

  8. Hello, thanks for this post! Could I ask about “Quick edit” and etc.. I’ve did what you said (also tried not only with “Properties”, but with “Defaults”), but when I execute script – it opens all PS windows without changed settings (so it has different font size, QuickEdit enabled , etc.) – it looks like script opens versions of PS with some different profile config. Could you tell please, how to save this properties config and make script to be able create new PS windows with these settings. Thanks again!!

    1. Hi Tomibeg, Thanks for your comment. This is interesting. You’re not running the script as admin are you? Probably not, but its worth to ask. What you might have to do then is in one of the open powershell windows, you change the default settings on one of those and save it.

      1. Thanks, Alex! For some reason even with Administrator rights it doesn’t save profile for windows created by script (regular windows which I manually create are opened with saved settings). But I think I found solution – I created script just to open custom PS window without chia, then changed config settings inside this window, and then it looks like all my new windows created by scripts also use these new settings. Looks like in my case PS uses independent config for script-opened instances.

  9. Thanks for this tutorial Alex. I have a question for you. I wanted to continuously plot to the final drive 52 time, is there a way to iterate on the “start-sleep” to space the delay an hour between each plot instead of manually filling out the different delay time 52 times?

    Thanks

    1. Hi Raffy, Thank you for your comment. If you want to plot 52 times you can set ‘-n’ to 52. This will make a queue of 52 plots.

  10. Also your initial run isn’t representative of future runs because the first plot has no competition for resources until the second plot runs, I figure out my overall time then take a smidge away from initial plots and add to later plots on the first run to get the spacing more equal.

  11. Hello Alex, thanks for that great tutorial!! It helped me to improve mine.

    Below is few things that I added in case that can help you or other people 😉

    Add log file:

    $Date = get-date -uformat “%Y%m%d%H%m”
    This is to create a date, then we can use $Date later to name our log file.

    | tee C:\Users\USER\Desktop\Logs\970_PRO_1_$date.log
    This creates the log file with date integrated, like this for example : 970_PRO_1_202105081205.log

    —–

    Add buzer:

    [console]::beep(800,500) ; start-sleep 300 ; [console]::beep(800,500)
    This will buzz 1 then sleep 5 mins then buzz again, you can add as many as you wish
    I added that to the first plot line, so I now when it’s done and I can launch a new ps1 file if needed.
    Or you can add it to the latest one and you will know when latest plot is done.

    —–

    At the end this is what it looks like with a exemple of 2 plots:

    invoke-expression ‘cmd /c start powershell -NoExit -Command {cd C:\Users\USER\AppData\Local\chia-blockchain\app-1.1.X\resources\app.asar.unpacked\daemon\;$host.ui.RawUI.WindowTitle = “970 PRO 1”; start-sleep 0 ; $Date = get-date -uformat “%Y%m%d%H%m” ; .\chia.exe plots create -k 32 -b 6750 -r 4 -u 128 -n 1 -f FARM KEY -p POOL KEY -t Z:\ -d K:\ | tee C:\Users\USER\Desktop\Logs\plot_970_PRO_1_$date.log ; [console]::beep(800,500) ; start-sleep 300 ; [console]::beep(800,500) ; Read-Host -Prompt “press enter to exit”}’

    invoke-expression ‘cmd /c start powershell -NoExit -Command {cd C:\Users\USER\AppData\Local\chia-blockchain\app-1.1.X\resources\app.asar.unpacked\daemon\;$host.ui.RawUI.WindowTitle = “970 PRO 2”; start-sleep 7200 ; $Date = get-date -uformat “%Y%m%d%H%m” ; .\chia.exe plots create -k 32 -b 6750 -r 4 -u 128 -n 5 -f FARM KEY -p POOL KEY -t Z:\ -d K:\ | tee C:\Users\USER\Desktop\Logs\plot_970_PRO_2_$date.log ; Read-Host -Prompt “press enter to exit”}’

    Note that I added -f FARM KEY & -p POOL KEY because this computer is a plotter only.

    Raph

  12. Hello Alex, thanks for that great tutorial!! It helped me to improve mine.

    Below is few things that I added in case that can help you or other people 😉

    Add log file:

    $Date = get-date -uformat “%Y%m%d%H%m”
    This is to create a date, then we can use $Date later to name our log file.

    | tee C:\Users\USER\Desktop\Logs\970_PRO_1_$date.log
    This creates the log file with date integrated, like this for example : 970_PRO_1_202105081205.log

    —–

    Add buzer:

    [console]::beep(800,500) ; start-sleep 300 ; [console]::beep(800,500)
    This will buzz 1 then sleep 5 mins then buzz again, you can add as many as you wish
    I added that to the first plot line, so I know when it’s done and I can launch a new ps1 file if needed.
    Or you can add it to the latest one and you will know when latest plot is done.

    —–

    At the end this is what it looks like with an exemple of 2 plots:

    invoke-expression ‘cmd /c start powershell -NoExit -Command {cd C:\Users\USER\AppData\Local\chia-blockchain\app-1.1.X\resources\app.asar.unpacked\daemon\;$host.ui.RawUI.WindowTitle = “970 PRO 1”; start-sleep 0 ; $Date = get-date -uformat “%Y%m%d%H%m” ; .\chia.exe plots create -k 32 -b 6750 -r 4 -u 128 -n 1 -f FARM KEY -p POOL KEY -t Z:\ -d K:\ | tee C:\Users\USER\Desktop\Logs\plot_970_PRO_1_$date.log ; [console]::beep(800,500) ; start-sleep 300 ; [console]::beep(800,500) ; Read-Host -Prompt “press enter to exit”}’

    invoke-expression ‘cmd /c start powershell -NoExit -Command {cd C:\Users\USER\AppData\Local\chia-blockchain\app-1.1.X\resources\app.asar.unpacked\daemon\;$host.ui.RawUI.WindowTitle = “970 PRO 2”; start-sleep 7200 ; $Date = get-date -uformat “%Y%m%d%H%m” ; .\chia.exe plots create -k 32 -b 6750 -r 4 -u 128 -n 5 -f FARM KEY -p POOL KEY -t Z:\ -d K:\ | tee C:\Users\USER\Desktop\Logs\plot_970_PRO_2_$date.log ; Read-Host -Prompt “press enter to exit”}’

    I added -f FARM KEY & -p POOL KEY because this computer is a plotter only.

    Raph

  13. Hi Alex,

    Thank you very much for your time and effort to help us.

    I have checked all my plots inside a HDD with command “.chia plots check” on Windows PowerShell and all of them are OK and not duplicatted, but when I connect them to farm on my iMac, there are 4 plots that doesn’t appear on Local Harvester Plots list, so they are not farming. ¿what is causing that? ¿Is any other way to know what is the problem with those plots, or is there a way of repair them? A cannot find any informations of this regard. Thaks a lot!!

    Rafa

    1. The total progress is a bit harder to do in PowerShell sadly. I’m sure there is a way, but I haven’t looked into it to see.

  14. Just wondering if I run Powershell script to plot, can I still have the GUI open for harvesting? Will the new plots made by powershell automatically show up under Farms in GUI or do I need to manually add those plots through the GUI?

    1. Yes, you can still have the GUI open. And the plots will automatically show up in the farmer as long as the final directory is the same.

Comments are closed.

%d bloggers like this: