-
Notifications
You must be signed in to change notification settings - Fork 398
Closed
Description
when running the PSScriptAnalyzer with default rules on this script, i keep getting the following error back:
RuleName Severity FileName Line Message
-------- -------- -------- ---- -------
PSShouldProcess Warning ConvertTo- 21 'ConvertTo-ShortPath' calls ShouldProcess/ShouldContinue
ShortPath. but does not have the ShouldProcess attribute.
ps1
here is the script, the SupportsShouldProcess, or SupportsShouldContinue is clearly not defined. This is the second time i have encountered this.
<#
.SYNOPSIS
Converts the path to the 8.3 short equivilent.
.DESCRIPTION
Converts the NTFS file or folder path to the MS-DOS 8.3 short path equivilent.
.INPUTS
System.String.
.OUTPUTS
System.String.
.PARAMETER Path
The path to be converted.
.EXAMPLE
PS C:\> ConvertTo-ShortPath -Path $env:ProgramFiles
C:\PROGRA~1
.NOTES
This function uses COM, and as such, permissions are needed to read the file or folder.
.LINK
https://dotps1.github.io
#>
function ConvertTo-ShortPath {
[CmdletBinding()]
[OutputType(
[String]
)]
param (
[Parameter(
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true
)]
[Alias(
"FullName"
)]
[String[]]
$Path
)
begin {
$fso = New-Object -ComObject Scripting.FileSystemObject
}
process {
foreach ($item in $Path) {
if (($item = Get-Item -Path $item).PSIsContainer) {
$fso.GetFolder(
$item.FullName
).ShortPath
} else {
$fso.GetFile(
$item.FullName
).ShortPath
}
}
}
end {
[Void][System.Runtime.InteropServices.Marshal]::ReleaseComObject(
$fso
)
Remove-Variable -Name fso
}
}
Metadata
Metadata
Assignees
Labels
No labels