Community discussions

 
navidrasi
just joined
Topic Author
Posts: 9
Joined: Sun Sep 18, 2011 11:22 pm

Powershell Module

Wed Jun 01, 2016 8:48 pm

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
You do not have the required permissions to view the files attached to this post.
 
bitplumber
just joined
Posts: 1
Joined: Thu Jun 02, 2016 4:35 am

Re: Powershell Module

Tue Jun 14, 2016 12:58 pm

Thanks mate, I was just thinking about something like this myself.  :)
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6267
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Powershell Module

Tue Jun 14, 2016 4:00 pm

thanks, added link in the API page to your creation.
 
fsbl
just joined
Posts: 1
Joined: Thu Sep 01, 2016 2:36 pm

Re: Powershell Module

Thu Sep 01, 2016 2:40 pm

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?
 
milan63
just joined
Posts: 2
Joined: Sun Jan 08, 2017 9:58 pm

Re: Powershell Module

Sun Jan 08, 2017 10:08 pm

Windows Server 2012 PS:
import-module d:\mikrotik.dll
error: HRESULT: 0x80131515
What can i do with it?
Can you help me please?
 
mitchellmnr
just joined
Posts: 2
Joined: Tue Mar 08, 2016 10:04 pm

Re: Powershell Module

Tue Mar 07, 2017 8:53 pm

@milan63 -
Try right click and say unblock.
* That should do the job

@navidrasi -
Would you consider open-sourcing and posting the code on GitHub?
 
milan63
just joined
Posts: 2
Joined: Sun Jan 08, 2017 9:58 pm

Re: Powershell Module

Wed May 24, 2017 7:20 pm

@mitchellmnr-
Perfect
Thank You !!!
 
nateingalls
just joined
Posts: 1
Joined: Thu Nov 09, 2017 5:35 pm

Re: Powershell Module

Thu Nov 09, 2017 6:16 pm

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!
 
vedodedo
just joined
Posts: 1
Joined: Sun Sep 30, 2018 3:12 pm

Re: Powershell Module

Sun Sep 30, 2018 3:16 pm

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

Who is online

Users browsing this forum: No registered users and 3 guests