Sorry Don, I didn’t see your reply.
I can do that, I just think that having the modules separate would make collaboration and maintainability easier.
Of course I could be way off base, especially since there are only a couple people developing powershell scripts in my group.
I’m developing on a Windows 8.1 machine with PS 4.0, but my code will mainly be run on Windows 7 with PS 3.0.
Here are the actual files, sorry for the wall of text, I can edit and attach as txt files if that’s what you want.
If you see a bug, or an easier way to do something, you can tell me, but that’s not the main reason of this post.
Misc.psd1
#
# Module manifest for module 'Misc'
#
# Generated by: astewa44
#
# Generated on: 10/3/2014
#
@{
# Script module or binary module file associated with this manifest.
RootModule = 'Misc.psm1'
# Version number of this module.
ModuleVersion = '0.0'
# ID used to uniquely identify this module
GUID = 'fa5f6060-9c8a-4527-9956-d8e37cea41bf'
# Author of this module
Author = 'Anthony Stewart'
# Company or vendor of this module
CompanyName = 'OIT@UTK'
# Copyright statement for this module
Copyright = '(c) 2014 Anthony Stewart. All rights reserved.'
# Description of the functionality provided by this module
Description = 'This module is a collection of funtions and cmdlets written by OIT, for OIT.'
# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''
# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()
# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @("GetComputerNumber.psm1", "RemoveRemoteItem.psm1")
# Functions to export from this module
FunctionsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = '*'
# List of all modules packaged with this module
# ModuleList = @()
# List of all files packaged with this module
# FileList = @()
# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''
# HelpInfo URI of this module
# HelpInfoURI = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}
Misc.psm1
Export-ModuleMember Get-ComputerNumber
Export-ModuleMember Remove-RemoteItem
GetComputerNumber.psm1
Get-ComputerNumber -Name "COM-NORTHD99"
99
#>
function Get-ComputerNumber
{
[CmdletBinding()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]
$Name
)
$CompNum = $Name
$CN = -1
for ($i = 0; ($i -lt $Name.Length) -and (-not [int32]::TryParse($CompNum, [ref]$CN)); $i++)
{
Write-Verbose $CompNum
$CompNum = $CompNum.Substring(1)
}
if ([string]::IsNullOrEmpty($CompNum))
{
Write-Verbose "Number not found"
return -1
}
else
{
Write-Verbose "Number found"
return $CN
}
}
RemoveRemoteItem.psm1
Remove-RemoteItem -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\R-core -ComputerNames "COM-NORTHD99" -Recurse
#>
function Remove-RemoteItem
{
[CmdletBinding()]
Param
(
# Path - The path to the item to be removed
[Parameter(Mandatory=$true,
Position=0)]
[string[]]
$Path,
# ComputerName - The computer names for the Remove-Item cmdlet to be run on
[Parameter(Mandatory=$true,
Position=1)]
[string[]]
$ComputerNames,
# Recurse - Passed directly to Remove-Item
[switch]
$Recurse,
# Force - Passed directly to Remove-Item
[switch]
$Force
)
# Hashtable for splatting the parameters to Remove-Item
$params = @{Path=$Path; Recurse=$Recurse; Force=$Force}
foreach ($computer in $ComputerNames)
{
# If the computer name is not the local computer
if ($computer -ne $env:COMPUTERNAME)
{
Invoke-Command -ComputerName $computer {Remove-Item @params}
}
else
{
Remove-Item @params
}
}
}