Skip to content

Instantly share code, notes, and snippets.

@mwjcomputing
Last active December 27, 2015 11:29
Show Gist options
  • Select an option

  • Save mwjcomputing/7318897 to your computer and use it in GitHub Desktop.

Select an option

Save mwjcomputing/7318897 to your computer and use it in GitHub Desktop.
function New-PoshSecTemplate {
[CmdletBinding()]
param(
## Baseline Parmerter Set
[Parameter(ParameterSetName='Baseline')]
[switch]$Baseline,
[Parameter(ParameterSetName='Baseline')]
[string]$BaselinePath
)
begin{
## Script Variables
$local:BaselinePrefix = "Processes"
$local:BaselineFileErrorMessage = "The path specified does not exist. The baseline was not saved."
}
process{
$local:object = Get-CimInstance -ClassName Win32_Process
}
end{
if($Baseline) {
$local:Filename = Get-DateISO8601 -Prefix $local:BaselinePrefix -Suffix ".xml"
if ($BaselinePath) {
if (Test-Path -Path $BaselinePath) {
$local:FilePath = Join-Path -Path $BaselinePath -ChildPath $local:Filename
} else {
Write-Warning -Message $local:BaselineFileErrorMessage
break
}
} elseif ($global:PoshSecBaselinePath) {
if (Test-Path -Path $global:PoshSecBaselinePath) {
$local:FilePath = Join-Path -Path $global:PoshSecBaselinePath -ChildPath $local:Filename
} else {
Write-Warning -Message $local:BaselineFileErrorMessage
break
}
} else {
$local:FilePath = Join-Path -Path $env:USERPROFILE\Documents -ChildPath $local:Filename
}
$local:object | Export-Clixml $local:FilePath
} else {
Write-Output $local:object
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment