Bitcoin Forum
May 02, 2024, 09:22:40 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: PowerShell and Bitcoin Core  (Read 531 times)
This is a self-moderated topic. If you do not want to be moderated by the person who started this topic, create a new topic.
vh (OP)
Hero Member
*****
Offline Offline

Activity: 699
Merit: 666


View Profile
June 20, 2017, 02:45:00 AM
 #1

Just sharing a few PowerShell commands that I recently worked out which may come in handy when working with your wallet in windows.

This requires PowerShell 5.0 for access to ConvertFrom-Json.

Code:
set-alias bitcoin-cli "C:\Program Files\Bitcoin\daemon\bitcoin-cli.exe"

#dump balance
bitcoin-cli listaddressgroupings | convertfrom-json | % { foreach ($group in $_) { foreach ($addr in $group) { write-host "$($addr[1])`t$($addr[0])`t($($addr[2]))" } } }

#dump keys*
bitcoin-cli listaddressgroupings | convertfrom-json | % { foreach ($group in $_) { foreach ($addr in $group) { $privkey = bitcoin-cli dumpprivkey $addr[0]; write-host "$($addr[0])`t$($privkey)`t($($addr[2]))" } } }


*as needed
Code:
#unlock for 60 seconds
bitcoin-cli walletpassphrase "my pass phrase" 60


The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
Inkhardy
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
December 18, 2017, 03:34:31 AM
 #2

Thanks, I was trying to learn learn it udemy but it's very hard to grasp.
immakingacoin
Member
**
Offline Offline

Activity: 98
Merit: 11


View Profile
January 29, 2018, 11:00:50 PM
 #3

If you are in Windows 7-10, open "My Documents" and the same way you would type in like "www.facebook.com" or something on an internet browser, go to the My Documents address bar and type "Powershell". And it will open a Windows Command line.

This link has a thing that you can Copy and Paste into the Command line (called a Script) that creates a Calculator that you can use. If you put in various things you can make apps that do different things.
https://gallery.technet.microsoft.com/scriptcenter/7e08cb64-f621-44b2-810b-dab3827755ce

Here are some older posts about Bitcoin and Powershell.

Hello All,

I am a hobbyist .Net developer and had been trying (unsuccessfully) to use the "Bitnet" project (http://sourceforge.net/projects/bitnet/) for a while.  I finally got fed up and decided to start from scratch, below you will find the "first-pass"/"proof of concept" implementation of some of the "more commonly" used bitcoind rpc calls.  Most of the work is in the string formatting, and you will still have to handle the json string that gets returned, but its a start, and hopefully someone will find it useful.

It makes use of Invoke-WebRequest command available in Powershell 4.0

Any input would be appreciated!  Feel free to use/distribute to your hearts content, I simply ask that any improvements or extensions make their way back to this thread.

Enjoy:
copy the following text into a new file and save it as PowerCoin.ps1

H07ZmHjToR9k3L6+FtInvboy3TQktffyrVKph2hRnhHmZwOu1zomf9kgVBThEaCLbo0Kb5VfSpesiTvmsCnNBiE= (Signed with my Tip Address)

Code:
##Title: PowerCoin
##Version: 0.01
##Date: 6/7/2014
##Author: jagallout
##Usage: It works best to dot source the .ps1 file (e.g. PS C:\[path to PowerCoin.ps1]> . .\PowerCoin.ps1 )
##This will prompt you for a username/password and for the Uri for the rpc server, then you can just call the methods by name (e.g. getinfo)
##Question: jagallout on bitcointalk.org
##Tips: 1GqrY1LSRD4N99LQn4ULhSSoJ79B7rtC6W


$cred = Get-Credential
$Uri = Read-Host "Specify RPC Server"

$p_jsonrpc = "`"jsonrpc`":2.0"
$p_id = "`"id`":1"

function execute
{

    param
    (
    $json
    );

    $result = Invoke-WebRequest -Uri $Uri -Method Post -ContentType "application/json-rpc" -Credential $cred -Body $json

    return $result.Content
}

function getInfo
{

    $json =
@"
{"method":"getinfo",$p_id, $p_jsonrpc}
"@

    return execute($json)

}

function getblockcount
{

    $json =
@"
{"method":"getblockcount",$p_id, $p_jsonrpc}
"@

    return execute($json)

}

function getbestblockhash
{

    $json =
@"
{"method":"",$p_id, $p_jsonrpc}
"@

    return execute($json)

}

function getdifficulty
{

    $json =
@"
{"method":"getdifficulty",$p_id, $p_jsonrpc}
"@

    return execute($json)

}

function getreceivedbyaddress
{

    Param
    (
    [string]$address,
    [int]$confirmations
    );

    $params = "[`"$address`",$confirmations]"
    
    $json =
@"
{"method":"getreceivedbyaddress","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@

    return execute($json)
    
}

function signmessage
{
    Param
    (
    [parameter(mandatory=$true)][string]$address,
    [parameter(mandatory=$true)][string]$message
    );

    $params = "[`"$address`",`"$message`"]"

    $json =
@"
"@

    return execute($json)
}

function verifymessage
{
    Param
    (
    [parameter(mandatory=$true)][string]$address,
    [parameter(mandatory=$true)][string]$signature,
    [parameter(mandatory=$true)][string]$message
    );

    $params = "[`"$address`",`"$signature`",`"$message`"]"
    
    $json =
@"
{"method":"verifymessage","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@

    return execute($json)
    
}

function getbalance
{

    Param
    (
    [string]$account,
    [int]$confirmations
    );
  
    if (!$account) {$account = ""}
    if (!$confirmations) {$confirmations = 6}
    
    $params = "[`"$account`", $confirmations]"

    $json =
@"
{"method":"getbalance","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@

    return execute($json)

}

function getaccount
{
    Param
    (
    [string]$account
    );

    $params = "[`"$account`"]"

    $json =
@"
{"method":"getaccount","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@

    return execute($json)
}

function getaccountaddress
{
    Param
    (
    [string]$account
    );
    
    $params = "[`"$account`"]"

    $json =
@"
{"method":"getaccountaddress","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@

    return execute($json)
}

function dumpprivkey
{
    Param
    (
    [parameter(mandatory=$true)][string]$address
    );

    $params = "[`"$address`"]"

    $json =
@"
{"method":"dumpprivkey","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@
    
    return execute($json)
}

function getnewaddress
{
    Param
    (
    [string]$account
    );
    
    $params = "[`"$account`"]"

    $json =
@"
{"method":"getnewaddress","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@
    return execute($json)
}

function gettransaction
{
    Param
    (
    [parameter(mandatory=$true)][string]$txid
    );

    $params = "[`"$txid`"]"

    $json =
@"
{"method":"gettransaction","params":$($params.ToString()), $p_id, $p_jsonrpc}
"@

    return execute($json)

}

Hey Guy, i wrote a script to monitor my mining rig by netcat latest log to Seashell because i am too tired to watch every via Teamviewer.

This is also script for auto relaunch Mining ClayMore. It may work with other Miner like ccminer, but i havent tested yet, so feel free to try. All script i wrote is batch, powershell and bash. Everything is clear code. You can check on your own.

Requirement:
- Powershell
- Windows 10 with SubSystem Linux included. ( You can try cygwin)

Why:
- Batch is good, but it is limited. Powershell can reach System Process Level Monitor.
- Windows Pipe is stupid. Command must finish before pipe to other. Linux is line by line pipe.

Step by Step Guide:
1. Install SubSystem Linux by following online guide:
https://msdn.microsoft.com/en-us/commandline/wsl/install-win10

TLD'R:
- Run in Powershell:
   Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
- Enable Developer Mode:
   https://www.ghacks.net/2015/06/13/how-to-enable-developer-mode-in-windows-10-to-sideload-apps/
- Run cmd and type "bash" (without quotes)

2. Copy all to your claymore directory. Make sure start-eth-edited.bat is same directory with file *Miner.exe

3. Edit file auto.txt. Change your email, Bot_email ,your *Miner.exe and Worker value. ( I use Gmail so if you use anything else, please edit mail config yourself)

4. Create shortcut start-eth-edited.bat to Startup Directory to run with Windows startup.

!!!! Windows file like .txt and .bat is free to edit. but .BASH (or any thing run inside BASH) must be edited by vim inside bash. If you edit .bash file inside windows, please contact me to fix. Linux file cant contain /r charater.

After success, you will receive mail like this. It contains link of seashells.io link.
http://prntscr.com/hii7re

Seashells.io will monitor your rig like this.
http://prntscr.com/hii8ay

Flow:
Start-eth-edited ---Loop---> auto.bat

auto.txt --variable--> auto.bat

auto.bat --call--> script/FindProcessMining.ps1  ; find top 15 process with Highest CPU

auto.bat --excute--> MiningProcess ; excute Mining Process if top process doesnt have Mining Process

auto.bat --call --> script/seashell-mail.bash ; Setup seashell and send to your email. After that, script seashell sleep forever to prevent bash close.


If you need any support or have any feed back, comment or email me: sangvohoang@vnoss.org

TODO Next:
- Fix all remain bug.
- Move from Mail to Messenger Facebook Bot. I am writing a Bot on Facebook Messenger but I dont have enough money to buy a vps contain data.
- Messenger Bot will have lot lot more feature than this. Include manage your own rigs on Messenger.

!!! Script is Free to use. But i need your help to improve the script. Please donate me at ETH Address: 0x0A7721Bef04B491F07cCd02102622E1CdcD84a76

Link: https://drive.google.com/file/d/14pGlf_1Cy-Ilhy4zLrH5Gk0IdICIMtGK/view?usp=sharing

It really is a pain to identify which GPU needs attention based on information available in Windows. 

The closest I have come to identifying a GPU index to its PCI slot is demonstrated in the below Powershell script.  But even then, each Windows install is different so this procedure can't really be reproduced.  I am posting this in case someone has come across a better method or can expand on this script.

The idea behind this script is to identify all PCI devices and their children in Windows.  Then, one has to unplug GPU by GPU and correlate the PCI device to a physical PCI slot.  Once you have this cross reference, you can disable the GPUs you need in order to identify them.  The disabled GPUs will output a ProblemCode other than zero in the script.

Required DeviceManagement Cmdlets:
https://gallery.technet.microsoft.com/Device-Management-7fad2388

Powershell Script:
https://pastebin.com/x3zzzgru

Powershell Output:


/c
immakingacoin
Member
**
Offline Offline

Activity: 98
Merit: 11


View Profile
January 29, 2018, 11:10:15 PM
 #4

Powershell Cmdlets
https://technet.microsoft.com/en-us/library/ff714569.aspx

Powershell Cookbook
http://www.reedbushey.com/86Windows%20Powershell%20Cookbook%203rd%20Edition.pdf

Powershell Videos
https://www.youtube.com/watch?v=wQOONLaozjQ&list=PL8U9xbzeyGGbV8pqFuMK9WZn69IyinIMF
immakingacoin
Member
**
Offline Offline

Activity: 98
Merit: 11


View Profile
January 29, 2018, 11:14:11 PM
 #5

PowerShell
https://github.com/clymb3r/PowerShell
https://github.com/SublimeText/PowerShell
https://github.com/RamblingCookieMonster/PowerShell
https://github.com/lazywinadmin/PowerShell
https://github.com/Azure/azure-powershell
https://github.com/Jackbennett/powershell
https://github.com/obscuresec/PowerShell
https://github.com/PyroTek3/PowerShell-AD-Recon
https://github.com/mattifestation/PowerShellArsenal
https://github.com/PowerShellMafia/PowerSploit
https://github.com/dahlbyk/posh-git
https://github.com/dfinke/powershell-for-developers
https://github.com/alexinslc/powershell
https://github.com/nullbind/Powershellery
https://github.com/PlagueHO/Powershell
https://github.com/dfinke/powershell
https://github.com/hsmalley/Powershell
https://github.com/stefanstranger/PowerShell
https://github.com/uxone/powershell
https://github.com/varonis/powershell
https://github.com/lgulliver/Powershell
https://github.com/vMotioned/PowerShell
https://github.com/zloeber/Powershell
https://github.com/OfficeDev/PnP-PowerShell
https://github.com/bpatra/powershell
https://github.com/pester/Pester
https://github.com/kmarquette/Powershell
https://github.com/PowerShell/PowerShell-Docs
https://github.com/BenjaminArmstrong/Hyper-V-PowerShell
https://github.com/splunk/splunk-reskit-powershell
https://github.com/MrPowerScripts/PowerScripts
https://github.com/petrsnd/Powershell
https://github.com/subTee/PoshRat
https://github.com/davehull/Kansa
https://github.com/CosmosKey/PSIS
https://github.com/besimorhino/powercat
https://github.com/janikvonrotz/PowerShell-PowerUp
https://github.com/SitecorePowerShell/Console
https://github.com/guitarrapc/PowerShellUtil
https://github.com/andrebocchini/sccm-powershell-automation-module
https://github.com/jenkinsci/powershell-plugin
https://github.com/cdhunt/WindowsAudioDevice-Powershell-Cmdlet
https://github.com/abswaxing/PowerShell
https://github.com/dotCipher/CoinBot
https://github.com/PProvost/vim-ps1
immakingacoin
Member
**
Offline Offline

Activity: 98
Merit: 11


View Profile
January 29, 2018, 11:21:08 PM
 #6

Microsoft Script Resources
https://gallery.technet.microsoft.com/scriptcenter
13stmfpa
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
January 31, 2018, 02:52:00 AM
 #7

holy cow!!! you should working for MSFT - Great work!
btctousd81
Sr. Member
****
Offline Offline

Activity: 434
Merit: 270


View Profile WWW
January 31, 2018, 12:17:31 PM
 #8

sorry for stupid question, but what does it do ?

i am new to powershell.

Thanks

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!