Skip to content

Instantly share code, notes, and snippets.

@norbinsh
Created June 13, 2015 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norbinsh/8c33862b25e4f4d72ab9 to your computer and use it in GitHub Desktop.
Save norbinsh/8c33862b25e4f4d72ab9 to your computer and use it in GitHub Desktop.
Test
#Requires -RunAsAdministrator
#Requires -Version 4.0
$VerbosePreference = 'Continue'
$DebugPreference = 'Continue'
$WarningPreference = 'Continue'
function Get-StartupItems {
[cmdletbinding()]
Param (
[Parameter(Valuefrompipeline=$true, Valuefrompipelinebypropertyname=$true)]
[string]$ComputerName = $env:COMPUTERNAME,
[Parameter()]
[System.Management.Automation.PSCredential]$credential,
[Parameter()]
[switch]$GridView
)
Begin {
$properties = 'User', 'Description', 'PSComputerName'
}
Process {
Write-Debug ('Performing operation "Test-Connection" on target "{0}".' -f $ComputerName)
if ( -not (Test-Connection -ComputerName $ComputerName -count 1 -quiet) ) {
return Write-Error ('Failed to communicate with target "{0}".' -f $ComputerName)
} else {
Write-Verbose ('Successfully performed operation "Test-Connection" on "{0}".' -f $ComputerName)
}
$CimObjectParameters = @{
'Classname' = 'Win32_StartupCommand'
'ComputerName' = $ComputerName
'ErrorAction' = 'stop'
}
if ($PSBoundParameters['credential']) {
$CimObjectParameters.credential = $credential
}
try {
Write-Debug ('Performing operation "Get-CimInstance" on target "{0}".' -f $ComputerName)
$StartupItems = Get-CimInstance @CimObjectParameters | Select-Object -Property $properties
Write-Verbose ('Successfully retreived CIM object data from target "{0}".' -f $ComputerName)
}
catch {
return Write-Error $_ -TargetObject $ComputerName
}
if ($GridView) {
$StartupItems | Out-GridView
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment