Page 1 of 1

Powershell Module

Posted: Wed Jun 01, 2016 8:48 pm
by navidrasi
Hi everyone ,
I am not an experienced programmer but i love Mikrotik and Powershell , so here is my simple mikrotik powershell cmdlet module
i hope you like it , Please let me know if you think we can improve it

it supports API and API-SSL , for more information about Filters and Attributes please check http://wiki.mikrotik.com/wiki/Manual:API

Thank you

Exmaples:

PS C:\>Import-Module Mikrotik.dll
PS C:\> Get-Command -Module Mikrotik

CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Connect-Mikrotik 1.0.0.0 Mikrotik
Cmdlet Disconnect-Mikrotik 1.0.0.0 Mikrotik
Cmdlet Send-Mikrotik 1.0.0.0 Mikrotik

#Connecting using API default port and save the connection object in C$ then we can use C$ to send commands
PS C:\> $C=Connect-Mikrotik -IPaddress 192.168.3.1 -UserName admin -Password password
Connected to 192.168.3.1 , Identity=TEST1

#Connecting using API-SSL default port
PS C:\> $C=Connect-Mikrotik -IPaddress 192.168.3.1 -UserName admin -Password password -UseSSL
Connected to 192.168.3.1 , Identity=TEST1

#Connecting using API-SSL on diffrenet port that 8729
PS C:\> $C=Connect-Mikrotik -IPaddress 192.168.3.1 -UserName admin -Password svgafara -UseSSL -Port 3323

#get all ethernet interface which is not disabled

PS C:\> Send-Mikrotik -Connection $C -Command "/interface/getall" -Filters "type=ether","disabled=false"

#add ip to ether 1
PS C:\> Send-Mikrotik -Connection $C -Command "/ip/address/add" -Attributes "interface=ether1","address=192.168.201.1/24"

#get ether1 ip addres
PS C:\> Send-Mikrotik -Connection $C -Command "/ip/address/getall" -Filters "interface=ether1"

#Close the connection
PS C:\> Disconnect-Mikrotik -Connection $C

Re: Powershell Module

Posted: Tue Jun 14, 2016 12:58 pm
by bitplumber
Thanks mate, I was just thinking about something like this myself.  :)

Re: Powershell Module

Posted: Tue Jun 14, 2016 4:00 pm
by janisk
thanks, added link in the API page to your creation.

Re: Powershell Module

Posted: Thu Sep 01, 2016 2:40 pm
by fsbl
Hello! I want to say thank you for your module.
And I ask how I can use the commands "set" and "remove" with this module?

Re: Powershell Module

Posted: Sun Jan 08, 2017 10:08 pm
by milan63
Windows Server 2012 PS:
import-module d:\mikrotik.dll
error: HRESULT: 0x80131515
What can i do with it?
Can you help me please?

Re: Powershell Module

Posted: Tue Mar 07, 2017 8:53 pm
by mitchellmnr
@milan63 -
Try right click and say unblock.
* That should do the job

@navidrasi -
Would you consider open-sourcing and posting the code on GitHub?

Re: Powershell Module

Posted: Wed May 24, 2017 7:20 pm
by milan63
@mitchellmnr-
Perfect
Thank You !!!

Re: Powershell Module

Posted: Thu Nov 09, 2017 6:16 pm
by nateingalls
Sorry to bump an old thread but I'm wondering how to run Torch through this module. I just need the first result Torch gives me and then end the command. I tried running the following:
Import-Module –Name "C:\location\of\Mikrotik.dll" -Verbose
$C=Connect-Mikrotik -IPaddress ip.of.mikrotik -UserName admin -Password ******
Send-Mikrotik -Connection $C -Command "/tool/torch" -Attributes "interface=bridge1" >torchresults.txt
Disconnect-Mikrotik -Connection $C
It returns
Connected to ip.of.mikrotik , Identity=MikrotikIdentity
then locks up. I am unable to even Ctrl+Break out of the code. I've verified this command works in the CLI of the Mikrotik.

Any help would be greatly appreciated!

Re: Powershell Module

Posted: Sun Sep 30, 2018 3:16 pm
by vedodedo
hello there

i have problem with this powershell script
cant gave count-only to the script !
i just want to have the number.
many thanks for your attention
kareem

Re: Powershell Module

Posted: Sun Jan 27, 2019 9:55 pm
by gbudny
Hello !

Module is great and helped me a lot :) works like a charm !
But I have the same issue while trying to get count only to the script :(
By the way, have you considered putting the source of module on GitHub and allow e.g us to contribute with issue, bugs resolving and improving it ? ;) - would be great for me.

Thanks !

Re: Powershell Module

Posted: Thu Jul 04, 2019 1:18 pm
by flydvorkin
After 6.45.1 update previous API authorization method is deprecated and dll is not working :-(
Can you update dll with new auth method?

Re: Powershell Module

Posted: Thu Jul 04, 2019 4:24 pm
by flydvorkin
In accordance with the API manual change source code in this function to:

Code: Select all

public bool Login(string username, string password)
{
Send("/login");
Send("=name=" + username);
Send("=password=" + password, true);
if (Read()[0] == "!done")
{
return true;
}
else
{
return false;
}
}
In attach - source and dll

Re: Powershell Module

Posted: Fri Jul 05, 2019 6:13 pm
by gbudny
Hey,

flydvorkin thanks a lot ! Have you planned to add it on git as a fork to let us work on this or report issues/bugs etc ?
I use API quite lot and would appreciate it ;)

Thanks

Re: Powershell Module

Posted: Tue Jul 23, 2019 4:55 pm
by flydvorkin
Have you planned to add it on git as a fork to let us work on this or report issues/bugs etc ?
I use API quite lot and would appreciate it ;)
Hi.
I don't know, i'm not C-programmer, just only find and fix auth procedure in accordance with official API manual.