Skip to content

Commit

Permalink
Merge pull request #62 from mod-posh/dev
Browse files Browse the repository at this point in the history
Refining the module
  • Loading branch information
jeffpatton1971 authored Sep 15, 2020
2 parents b8268cc + 5127832 commit cfcdd22
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 1,894 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
- Update module for current PowerShell

## [1.1.2.1] - 2020-09-15
### Updated
- Issue #59 Change plural functions to singular

### Removed
- Issue #39 Remove functions not relevant to this module

## [1.1.2.0] - 2020-09-14
### Removed
- Issue #55 Remove New-ScheduledTask
Expand Down
18 changes: 9 additions & 9 deletions ComputerManagement/ComputerManagement.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'ComputerManagement.psm1'

# Version number of this module.
ModuleVersion = '1.1.2.0'
ModuleVersion = '1.1.2.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -69,13 +69,13 @@ Description = 'A PowerShell module for working with the local computer'
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Set-Pass', 'Get-CimService', 'Get-NonStandardServiceAccount',
'Get-PendingUpdates', 'Get-ServiceTag', 'Backup-EventLogs',
'Export-EventLog', 'Get-PaperCutLogs', 'Set-ShutdownMethod',
'Get-PrinterLogs', 'Get-OpenSessions', 'Get-OpenFiles',
'Get-RDPLoginEvents', 'Get-InvalidLogonAttempts', 'Get-MappedDrives',
'Get-DiskUsage', 'Get-Namespace', 'New-Password', 'Connect-Rdp',
'Get-NetShare', 'Get-WinEventTail', 'Open-CdDrive',
FunctionsToExport = 'Set-Pass', 'Get-CimService', 'Get-NonStandardServiceAccount',
'Get-PendingUpdates', 'Get-ServiceTag', 'Backup-EventLogs',
'Export-EventLog', 'Get-PaperCutLogs', 'Set-ShutdownMethod',
'Get-PrinterLogs', 'Get-OpenSessions', 'Get-OpenFiles',
'Get-RDPLoginEvents', 'Get-InvalidLogonAttempts', 'Get-MappedDrives',
'Get-DiskUsage', 'Get-Namespace', 'New-Password', 'Connect-Rdp',
'Get-NetShare', 'Get-WinEventTail', 'Open-CdDrive',
'Grant-RegistryPermission', 'New-Credential'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down Expand Up @@ -120,7 +120,7 @@ PrivateData = @{
# ExternalModuleDependencies = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
Expand Down
221 changes: 16 additions & 205 deletions ComputerManagement/ComputerManagement.psm1
Original file line number Diff line number Diff line change
@@ -1,62 +1,3 @@
Function Set-Pass {
[OutputType([System.String])]
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Set-Pass.md#set-pass',
SupportsShouldProcess,
ConfirmImpact = 'Low')]
Param
(
[Parameter(Mandatory = $true)]
[string]$ComputerName,
[Parameter(Mandatory = $true)]
[string]$UserName,
[Parameter(Mandatory = $true)]
[securestring]$Password
)
Begin {
}
Process {
Try {
if ($PSCmdlet.ShouldProcess("Change", "Change password for $($UserName)")) {
$User = [adsi]("WinNT://$ComputerName/$UserName, user")
$User.psbase.invoke("SetPassword", ($Password | ConvertFrom-SecureString -AsPlainText))

Return "Password updated"
}
}
Catch {
Return $Error[0].Exception.InnerException.Message.ToString().Trim()
}
}
End {
}
}
Function Get-CimService {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-CimService.md#get-cimservice')]
Param
(
[string]$Computer = (& hostname),
[pscredential]$Credential,
[string]$State = "Running",
[string]$StartMode = "Auto"
)
Begin {
}
Process {
If ($Computer -eq (& hostname)) {
$Services = Get-CimInstance -ClassName Win32_Service -Filter "State = '$State' and StartMode = '$StartMode'"
}
Else {
If ($null -eq $Credential) {
$Credential = Get-Credential
}
$Services = Get-CimInstance -ClassName Win32_Service -Filter "State = '$State' and StartMode = '$StartMode'" `
-ComputerName $Computer -Credential $Credential
}
}
End {
Return $Services
}
}
Function Get-NonStandardServiceAccount {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-NonStandardServiceAccount.md#get-nonstandardserviceaccount')]
Param
Expand Down Expand Up @@ -90,8 +31,8 @@ Function Get-NonStandardServiceAccount {
Return $Suspect
}
}
Function Get-PendingUpdates {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-PendingUpdates.md#get-pendingupdates')]
Function Get-PendingUpdate {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-PendingUpdate.md#get-pendingupdate')]
Param
(
[Parameter(ValueFromPipeline = $True)]
Expand Down Expand Up @@ -148,8 +89,8 @@ Function Get-ServiceTag {
Return $Return
}
}
Function Backup-EventLogs {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Backup-EventLogs.md#backup-eventlogs')]
Function Backup-EventLog {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Backup-EventLog.md#backup-eventlog')]
Param
(
[string]$ComputerName,
Expand Down Expand Up @@ -251,85 +192,8 @@ Function Export-EventLog {
End {
}
}
Function Get-PaperCutLogs {
[OutputType([Object[]])]
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-PaperCutLogs.md#get-papercutlogs')]
Param
(
$PrintServers = @("ps1.company.com", "ps2.company.com")
)
Begin {
# Location of the monthly PaperCut logs
$PcutLogLocation = "c$\Program Files (x86)\PaperCut Print Logger\logs\csv\monthly"
# Column headings in the CSV
$PcutHeader = "Time", "User", "Pages", "Copies", "Printer", "Document Name", "Client", "Paper Size", "Language", "Height", "Width", "Duplex", "Grayscale", "Size"
# Need it set to stop in order for the try/catch to work
$ErrorActionPreference = "Stop"
# Define an empty array to hold all the log entries
$PcutReport = @()
}
Process {
foreach ($PrintServer in $PrintServers) {
# Get each log file from the server
Try {
$PcutLogs = Get-ChildItem "\\$($PrintServer)\$($PcutLogLocation)"
}
Catch {
# This runs only if we're trying to pull logs from an x86 print server
$PcutLogs = Get-ChildItem "\\$($PrintServer)\c$\Program Files\PaperCut Print Logger\logs\csv\monthly"
}

Foreach ($PcutLog in $PcutLogs) {
# Import the csv into a variable, skip 1 skips the first line of the PaperCut CSV
# which has information not related to the log itself
$ThisReport = Import-Csv $PcutLog.FullName -Header $PcutHeader | Select-Object -Skip 1

# Add this log to the array
$PcutReport += $ThisReport | Where-Object { $_.Time -ne "Time" }
}
}
}
End {
# Display the result, this can be piped into Export-CSV to generate a large
# spreadsheet suitable for analysis
Return $PcutReport
}
}
Function Set-ShutdownMethod {
[OutputType([System.String])]
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Set-ShutdownMethod.md#set-shutdownmethod',
SupportsShouldProcess,
ConfirmImpact = 'High')]
PARAM
(
[parameter(Mandatory = $True, ValueFromPipeline = $True)]
[string]$ComputerName,
[pscredential]$Credentials = (Get-Credential),
[int32]$ShutdownMethod = 0
)
Begin {
}
Process {
Try {
if ($PSCmdlet.ShouldProcess("Shutdown", "Shutdown $($ComputerName)")) {
$ReturnValue = (Get-CimInstance -Class Win32_OperatingSystem -ComputerName $ComputerName -Credential $Credentials).InvokeMethod("Win32Shutdown", $ShutdownMethod)
}
}
Catch {
$ReturnValue = $Error[0]
}
}
End {
if ($ReturnValue -ne 0) {
Return "An error occurred, most likely there is nobody logged into $($ComputerName)"
}
else {
Return "Success"
}
}
}
Function Get-PrinterLogs {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-PrinterLogs.md#get-printerlogs')]
Function Get-PrinterLog {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-PrinterLog.md#get-printerlog')]
Param
(
$LogName = "Microsoft-Windows-PrintService/Operational",
Expand Down Expand Up @@ -373,8 +237,8 @@ Function Get-PrinterLogs {
Return $PrintLogs
}
}
Function Get-OpenSessions {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-OpenSessions.md#get-opensessions')]
Function Get-OpenSession {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-OpenSession.md#get-opensession')]
Param
(
$ComputerName = (hostname)
Expand Down Expand Up @@ -404,8 +268,8 @@ Function Get-OpenSessions {
Return $ServerSessions
}
}
Function Get-OpenFiles {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-OpenFiles.md#get-openfiles')]
Function Get-OpenFile {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-OpenFile.md#get-openfile')]
Param
(
$ComputerName = (hostname)
Expand Down Expand Up @@ -434,9 +298,9 @@ Function Get-OpenFiles {
Return $OpenFiles
}
}
Function Get-RDPLoginEvents {
Function Get-RDPLoginEvent {
[OutputType([Object[]])]
[cmdletbinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-RDPLoginEvents.md#Get-rdploginevents')]
[cmdletbinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-RDPLoginEvent.md#Get-rdploginevent')]
Param
(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
Expand Down Expand Up @@ -479,8 +343,8 @@ Function Get-RDPLoginEvents {
Return $LoginAttempts
}
}
Function Get-InvalidLogonAttempts {
[cmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-InvalidLogonAttempts.md#get-invalidlogonattempts')]
Function Get-InvalidLogonAttempt {
[cmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-InvalidLogonAttempt.md#get-invalidlogonattempt')]
Param
(
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
Expand Down Expand Up @@ -515,8 +379,8 @@ Function Get-InvalidLogonAttempts {
Return $Report
}
}
Function Get-MappedDrives {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-MappedDrives.md#get-mappeddrives')]
Function Get-MappedDrive {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-MappedDrive.md#get-mappeddrive')]
Param
(
[string]$ComputerName = (hostname),
Expand Down Expand Up @@ -589,30 +453,6 @@ Function Get-DiskUsage {
End {
}
}
Function Get-Namespace {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Get-Namespace.md#get-namespace')]
Param
(
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$Namespace,
[parameter(Mandatory = $true)]
[string]$ComputerName
)
Begin {
Write-Verbose 'Create an SWbemLocator object to connect to the computer'
$WbemLocator = New-Object -ComObject "WbemScripting.SWbemLocator"
Write-Verbose "Make a connection to $($ComputerName) and access $($Namespace)"
$WbemServices = $WbemLocator.ConnectServer($ComputerName, $Namespace)
Write-Verbose "Use the SubClassesOf() method of the SWbemServices object to return an SWbemObjectSet"
$WbemObjectSet = $WbemServices.SubclassesOf()
}
Process {
}
End {
Write-Verbose 'Return the Path_ property of the ObjectSet as this seems to contain useful information'
Return $WbemObjectSet | Select-Object -Property Path_ -ExpandProperty Path_
}
}
Function New-Password {
[OutputType([System.Object[]])]
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/New-Password.md#new-password',
Expand Down Expand Up @@ -762,35 +602,6 @@ Function Get-WinEventTail {
End {
}
}
function Open-CdDrive {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Open-CdDrive.md#open-cddrive')]
param
(
[string]$Drive
)
Begin {
$sApplication = new-object -com Shell.Application
$MyComputer = 17
}
Process {
if ($Drive) {
$Cdrom = $sApplication.Namespace(17).ParseName($Drive)
$Cdrom.InvokeVerb("Eject")
$Cdrom
}
else {
$Cdrom = $sApplication.NameSpace($MyComputer).Items() | Where-Object -Property Type -eq 'CD Drive'
foreach ($Cd in $Cdrom) {
$Cd.InvokeVerb('Eject')
$cd
}
}
}
end {
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($sApplication) | Out-Null
Remove-Variable sApplication
}
}
Function Grant-RegistryPermission {
[CmdletBinding(HelpURI = 'https://github.com/mod-posh/ComputerManagement/blob/master/docs/Grant-RegistryPermission.md#grant-registrypermission')]
Param
Expand Down
Loading

0 comments on commit cfcdd22

Please sign in to comment.