SmbConnector

SmbConnector

Source:

The WSH (Windows Script Host) CLI that connects to SMB resources according to the schema defined in a JSON file.

Requires

Methods

(static) connectSyncSurelyUsingLog(comp, shareNameopt, domainopt, useropt, pwdopt, optionsopt) → {void}

Source:

Connects the Windows to the shared resource

Example
var smbcn = Wsh.SmbConnector; // Shorthand

var comp = '11.22.33.44';
var share = 'public';
var domain = 'PCNAME';
var user = 'UserId';
var pwd = 'My * P@ss><';

smbcn.connectSyncSurelyUsingLog(comp, share, domain, user, pwd, {
  logger: 'warn/winEvent', // See https://github.com/tuckn/WshLogger
  showsResult: true
});
Parameters:
Name Type Attributes Default Description
comp string

The computer name

shareName string <optional>
'IPC$'

The share name

domain string <optional>
''

The domain name. If it is empty, net use uses the current logged on domain.

user string <optional>

The user name with which to log on

pwd string <optional>

The password. *: produce a prompt for the password.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
logger Logger | string | object <optional>

The Logger instance or create options. See Wsh.Logger.create.

transportsLog boolean <optional>
true

Outputs Wsh.Logger logs after connecting. See Wsh.Logger.transport.

throws boolean <optional>
false

Throws the error, if SMB connecting throws an error.

showsResult boolean <optional>
false

Shows the current session after connecting.

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
Type
void

(static) connectSyncUsingSchema(schema, taskNameopt, optionsopt) → {void|string}

Source:

Connects the Windows to the shared resources

Example
var smbcn = Wsh.SmbConnector; // Shorthand
var schema = {
  components: {
    ipc: 'IPC$',
    homeNasIP: '127.0.0.10',
    workNetDomain: 'mycompany.local',
    workUsername: 'ID123456',
    anyVal1: null, // Overwrites with options.overwrites.anyVal1
    anyVal2: null // Overwrites with options.overwrites.anyVal2
  },
  tasks: {
    home: {
      comp: '${homeNasIP}',
      share: '${ipc}',
      user: 'tuckn',
      pwd: '${anyVal1}'
    },
    'work:office': {
      available: false,
      comp: 'SV12345',
      share: '${ipc}',
      domain: '${workNetDomain}',
      user: '${workUsername}',
      pwd: '{$anyVal2}'
    },
    'work:labo': {
      description: 'Test Server (Windows Server2008)',
      available: true,
      comp: 'PC67890',
      share: 'C$',
      domain: 'PC67890',
      user: '${workUsername}',
      pwd: '{$anyVal2}'
    }
  }
}

smbcn.connectSyncUsingSchema(schema, 'work:*', {
  logger: 'info/console',
  showsResult: true,
  overwrites: { anyVal1: 'myHomeP@ss', anyVal2: 'officeP@ss' }
});
// Only process work:labo. work:office is not processed because available is false.
// command is `net use \\PC67890\C$ myP@ss /user:PC67890\ID123456`
Parameters:
Name Type Attributes Description
schema typeNetSmbsmbConnectorSchema
taskName string <optional>

The task name to connect

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
overwrites object <optional>

Ex. { anyVal1: 'myP@ss', anyVal2: 'p_w_d' }

logger string | Object <optional>

See options of Wsh.Logger.create

showsResult boolean <optional>
false

Shows the current session after connecting.

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
  • If options.isDryRun is true, returns string.
Type
void | string