'Importing a custom module in Powershell

I'm trying to figure out how I can import custom modules into my powershell script that I've created.

Initially, I created device information class psm1 module:

class DeviceInformation {
    class DeviceInformation {
    [string]$DeviceName
    [string]$DeviceManufacturer
    [string]$DeviceModel
    [string]$DeviceSerialNumber
    [string]$DevicePhysicalMACAddress

    DeviceInformation() {
        $this.DeviceName                    = $env:COMPUTERNAME;
        $this.DeviceManufacturer            = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Manufacturer -ExpandProperty Manufacturer;
        $this.DeviceModel                   = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Model -ExpandProperty Model;
        $this.DeviceSerialNumber            = Get-WmiObject Win32_BIOS | Select-Object SerialNumber -ExpandProperty SerialNumber;
        $this.DevicePhysicalMACAddress      = (Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $this.DeviceName | Where-Object{$_.IpEnabled -Match "True"} | Select-Object -Expand MacAddress) -join ", ";
    }

    [string]GetDeviceName() {
        return $this.DeviceName;
    }

    [string]GetDeviceManufacturer() {
        return $this.DeviceManufacturer;
    }

    [string]GetDeviceModel() {
        return $this.DeviceModel;
    }

    [string]GetDeviceSerialNumber() {
        return $this.DeviceSerialNumber;
    }

    [string]GetDevicePhysicalMACAddress() {
        return $this.DevicePhysicalMACAddress;
    }
}
}

This is named "device_information.psm1".

Initially, I "imported" the script in using:

Using Module ".\device_information.psm1"

That worked like I expected it to.

I've now decided that I would like to shift my GUI window code into its own class to try and condense my code down (I'll also likely have all of my window "components" in their own module classes too).

However, I quickly realised I cannot have two Using Module statements.

How would I go about doing this so I can have other modules imported where I need them? I've had a look into Import-Module but by the look of that, I need to save the files in a specific place on the device... Not quite what I want as this will be used on a whole heap of devices so I want it to be as painless for me and the persons using it.

Cheers



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source