Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Set-FileAssociation {
- Param (
- [Parameter(Mandatory)][string[]]$Extension,
- [Parameter(Mandatory)][ValidateScript({ Test-Path $_ })][string]$Path
- )
- foreach ($e in $Extension) {
- $e = $e -replace '\A\.?', '.'
- $fileType = (cmd /c "assoc $e") -split '='
- if ($fileType.Count -eq 2) {
- $fileType = $fileType[1]
- cmd /c "ftype $fileType=""$Path"" ""%1"""
- } else {
- Write-Error "Could not determine association for extension $e."
- }
- }
- }
- function Get-FileAccociation {
- param ([string]$FileType = '*')
- cmd /c ftype | Select-String -Pattern '(.*?)=(.*)' | % { [pscustomobject]@{ FileType = $_.Matches[0].Groups[1].Value; Association = $_.Matches[0].Groups[2].Value } } | ? FileType -Like $FileType
- }
Advertisement
Add Comment
Please, Sign In to add comment