Skip to content

kevinjjworld/TrueNAS-Powershell-Module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

167 Commits
 
 
 
 
 
 

Repository files navigation

TrueNAS-Administration

This is a Powershell Module that provides command-lines and automation for the TrueNAS API.

With this module, you can manage your TrueNAS server from a computer with Powershell (Windows and Linux).

  • This module only works over HTTPS.
  • This module only works with TrueNAS API Key.

Requirements

  • Powershell 7.1 Minimum (for a better experience) but works on Powershell 5.1 Minimum
  • TrueNAS RESTful API 2.0

How to install Powershell 7 ?

Install the module from PSGallery

Example 1 - For Current User :

Install-Module -Name "TrueNAS-Administration" -Scope CurrentUser -Force

Example 2 - For All Users :

Install-Module -Name "TrueNAS-Administration" -Scope AllUsers -Force

-Scope AllUsers need admin rights.

Import the Module in Powershell

1. Set Execution Policy (Only for Powershell 5.1) :

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
  • Use -Scope CurrentUser to persist ExecutionPolicy for Current User.
  • Use -Scope LocalMachine to persist ExecutionPolicy for All Users.

2. Import the module :

Import-Module -Name "TrueNAS-Administration" -Force

3. List all module's Cmdlets :

Get-Command -Module "TrueNAS-Administration"

Update the Module

1. Check the latest available version of the module :

Find-Module -Name "TrueNAS-Administration"

2. Update the module

Update-Module -Name "TrueNAS-Administration" -Force

Usage

1. Get a session and store it in a variable

  • If you have a valid certificate :
$Session = Get-TrueNasSession -Server "truenas" -APIToken "1-xxxxxxxxxxx"
  • If you don't have a valid certificate, use the parameter -SkipCertificateCheck :
$Session = Get-TrueNasSession -Server "truenas" -APIToken "1-xxxxxxxxxxx" -SkipCertificateCheck

2. Run Cmdlets using the previous variable containing the session. For example :

Get-TrueNasInfo -TrueNasSession $Session

Examples

List TrueNAS users

Get-TrueNasUser -TrueNasSession $Session

Create a new user

  • Example 1 :
New-TrueNasUser -TrueNasSession $Session -Credential "userName" -FullName "My New User" `
                -MicrosoftAccount -SambaAuthentification

You will be prompted for the users's password. If you need a non-interactive command, see Example 2.

  • Example 2 :
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList @(
        "userName", $(ConvertTo-SecureString -String "userPassword" -AsPlainText -Force)
)

New-TrueNasUser -TrueNasSession $Session -Credential $Cred -FullName "My New User" `
                -MicrosoftAccount -SambaAuthentification

This method is less secure because the password is written in clear text in the command line history.

List TrueNAS groups :

Get-TrueNasGroup -TrueNasSession $Session

Create a new group :

New-TrueNasGroup -TrueNasSession $Session -GroupName "groupName" -SambaGroup

About

TrueNAS Powershell Module

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors