diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..12d48f1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "git.autofetch": false +} \ No newline at end of file diff --git a/AlphaFS.dll b/AlphaFS.dll deleted file mode 100644 index 7f13faa..0000000 Binary files a/AlphaFS.dll and /dev/null differ diff --git a/Changelog.md b/Changelog.md new file mode 100644 index 0000000..37528ff --- /dev/null +++ b/Changelog.md @@ -0,0 +1,59 @@ + v2.0.0.0 + - Major Release with numerous improvements and enhancements + - Module is now compatible with PS v3 + - Module now uses Alphafs.dll v2.1.2(latest at the moment of this writing) + - All cmdlets work with relative paths + - New features\improvements in Existing Cmdlets + - Get-LongChildItem + - Lists directory items immediately and dosent wait until it is done enumerating the complete directory tree + - By default ignores errors(access denied) encountered during directory enumeration. + - Uses a simplified logic to enumerate the filesystem and work with include and exclude parameters + - Symlinks are now shown by default and the cmdlet optionally adds a switch parameter(-SkipSymbolicLink) to hide listing them. + - The mode property now indicates whether a particular file or directory is a SymbolicLink + - filehash algorith SHA256 + - Additional properties added + - FileHash + - Target + - PSIsContainer + - LinkType + - IsPathLong + - IsSymbolicLink + - IsDirectory + - IsCompressed + - IsHidden + - IsEncrypted + - IsMountPoint + - IsOffline + - New-LongItem + - Create Symbolic Links for files and folders + - Create HardLinks for files + - Create text files and optionally add text content( can be an array of strings) with user specified encoding + - Remove-LongItem + - Added the ability to remove a file or folder with a trailing space in the name + - Rename-LongItem + - Added the ability to rename\change file extension while retaining the file name.(-NewExtension Parameter) + - Copy-LongChildItem + - New Switch Parameters + - CopySymbolicLink + - (If the source file is a symbolic link, destination is also a symbolic link pointing to the same file) + - Not working at this moment.(github issue raised - https://github.com/alphaleonis/AlphaFS/issues/292) + - NoBuffering + - (copy is performed using unbuffered I/O. Recommended for very large file transfers.) + - AllowDecryptedDestination + - (An attempt to copy an encrypted file will succeed even if the destination copy cannot be encrypted.) + - New Cmdlets + - Mount-LongShare + - Map Network share with or without credentials. + - DisMount-LongShare + - Remove mapped drive. + - Get-LongMappedDrive + - List mapped drives on localmachine. + - use format-list to view the UncPath property which shows the sharepath + - Get-LongFreeDriveLetter + - Be default gets the first free driveletter and with the -last parameter will list the last free drive letter. + - Get-LongDiskDrive + - Gets diskspace stats(used\free\percent). + - Get-LongDirectorySize + - Gets the size of a folder. + - Specify -Recurse to include subfolders and files + - Specify -ContinueonError to ignore errors(may result in an incorrect directory size) \ No newline at end of file diff --git a/Examples.md b/Examples.md new file mode 100644 index 0000000..67df3e5 --- /dev/null +++ b/Examples.md @@ -0,0 +1,480 @@ +NAME + Copy-LongItem + +SYNOPSIS + Copies an item from one location to another. + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Copy-LongItem -Path C:\temp\drivers.txt -Destination C:\temp\folder1 -Verbose + + + This command copies the drivers.txt file to the C:\temp\folder1 directory. 'folder1' is created if it dosent exist. + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Copy-LongItem C:\temp\logfiles -Destination C:\temp\newlogs + + + This command copies the contents of the C:\Logfiles directory recursively to the C:\temp\newLogs directory. It creates the \newLogs subdirectory if it does not already exist. + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\>Copy-LongItem -Path C:\temp\win2012R2.iso -Destination C:\temp\2012R2.iso -Verbose -NoBuffering + + + attempts to copy the iso file using unbuffered I/O + +NAME + DisMount-LongShare + +SYNOPSIS + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>DisMount-LongShare -DriveLetter F: + + + Unmounts any network share that is mounted on F: + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>DisMount-LongShare -DriveLetter G -Force + + + Any open files or connections to the G drive are dropped and then the G drive is unmounted . + +NAME + Get-LongChildItem + +SYNOPSIS + Gets the items and child items in one or more specified locations. + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Get-LongChildItem -Path C:\temp -Filter d*.txt -Recurse + + + Directory: C:\temp + + Mode LastWriteTime Length Name + ---- ------------- ------ ---- + File 6/27/2015 11:44 AM 1488 drivers.txt + File 7/3/2015 12:30 PM 72 dupes.txt + + + Directory: C:\temp\folder4\DSC06252 + + Mode LastWriteTime Length Name + ---- ------------- ------ ---- + File 8/23/2015 6:24 PM 93 dupes.txt + + + This command gets all of the files that begin with the letter 'd' followed by any character(s) but end with the extension 'TXT' in the path directory and its subdirectories. The Recurse parameter directs Windows + PowerShell to get objects recursively, and it indicates that the subject of the command is the specified directory and its contents. + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Get-LongChildItem –Path C:\temp -Include *.txt -Exclude A*,c*,e* + + + This command lists the .txt files in the temp directory, except for those whose names start with the letter A or C or E. + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\>Get-LongChildItem –Path C:\windows\System32\WindowsPowerShell -Filter about*.txt -Recurse -Name + + + This command gets only the names of all Text files that begin with 'about' in the C:\windows\System32\WindowsPowerShell directory and its subdirectories. + -------------------------- EXAMPLE 4 -------------------------- + + PS C:\>Get-LongChildItem –Path C:\temp -Name -Directory -Recurse + + + This command gets only the names of all directories in the C:\temp directory and its subdirectories. + -------------------------- EXAMPLE 5 -------------------------- + + PS C:\>Get-LongChildItem -Path C:\temp -Recurse | Where PathLength -gt 260 + + + This command gets all files and folders recursively. The output is then piped to Where-object which displays only those files whose length exceeds the windows API 260 character length limitation. + -------------------------- EXAMPLE 6 -------------------------- + + PS C:\>Get-LongChildItem -Path D:\Temp + + + Directory: D:\Temp + + Mode LastWriteTime Length Name + ---- ------------- ------ ---- + Directory 12/5/2016 9:44 PM 123 + File 12/23/2016 2:46 PM 9491 temp.ps1 + SymLink-f 12/7/2016 7:21 PM 0 MySymLinkFile.txt + SymLink-f 12/17/2016 12:38 PM 0 MySymLinkFile2.txt + SymLink-d 12/17/2016 12:47 PM symfolder1 + SymLink-d 12/17/2016 12:49 PM symfolder2 + File 12/25/2016 2:10 AM 4405 test.ps1 + File 12/11/2016 1:52 PM 3 testfile1.txt + Directory 12/11/2016 2:26 PM testmodule + File 12/11/2016 2:02 PM 3 thirdfile.txt + + + The mode property now shows whether a file or folder is a symlink(symboliclink) and additionaly indicates whether the type is a file or a directory + -------------------------- EXAMPLE 7 -------------------------- + + PS C:\>Get-LongChildItem -Path D:\Temp -SkipSymbolicLink + + + Directory: D:\Temp + + Mode LastWriteTime Length Name + ---- ------------- ------ ---- + Directory 12/5/2016 9:44 PM 123 + File 12/23/2016 2:46 PM 9491 temp.ps1 + File 12/25/2016 2:10 AM 4405 test.ps1 + File 12/11/2016 1:52 PM 3 testfile1.txt + Directory 12/11/2016 2:26 PM testmodule + File 12/11/2016 2:02 PM 3 thirdfile.txt + + + lists all items in d:\temp with the exception of symboliclinks + -------------------------- EXAMPLE 8 -------------------------- + + PS C:\temp>Get-LongChildItem testdir + + + gets items from the folder 'testdir' located in c:\temp + +NAME + Get-LongDirectorySize + +SYNOPSIS + Gets the properties of a directory without following any symbolic links or mount points. + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Get-LongDirectorySize -Path D:\Github -Recurse + + Key Value + --- ----- + Archive 321 + Compressed 0 + Device 0 + Directory 201 + Encrypted 0 + Hidden 1 + IntegrityStream 0 + Normal 0 + NoScrubData 0 + NotContentIndexed 0 + Offline 0 + ReadOnly 264 + ReparsePoint 0 + SparseFile 0 + System 0 + Temporary 0 + File 321 + Total 522 + Size 3069696 + SizeinMB 3 + + + Gets the directory statistics for D:\Github, optionally enumerating the subfolders and files. + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Get-LongDirectorySize -ContinueonError + + + Enumerates the files and folders in the current directory, and will ignore any exceptions\errors that may arise due to access or other issues. + Warning: using the -ContinueonError may result in an incorrect directory size. + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\>$githubDIR = Get-LongDirectorySize D:\Github -Recurse + + $githubDIR.Size + 3069696 + + $githubDIR.SizeinMB + 3 + + PS C:\temp\dsc> + + + The first command assigns the out of the cmdlet Get-LongDirectorySize to the variable github + the second command is used to access the size of the directory in bytes. + the third command lists the size in megabytes. + + Note: the unit of size kb\mb\gb\tb will change based on the size of the directory. + +NAME + Get-LongDiskDrive + +SYNOPSIS + List local and mapped drives on the local machine along with their size,freespace and usedspace. + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Get-LongDiskDrive + + DriveLetter VolumeLabel FileSystem DriveType FreePercent UsedPercent Free Used Size + ----------- ----------- ---------- --------- ----------- ----------- ---- ---- ---- + A:\ Unknown Removable 0.00% 0.00% 0 B 0 B 0 B + C:\ NTFS Fixed 19.83% 80.17% 9.84 GB 39.81 GB 49.66 GB + D:\ Source NTFS Fixed 32.67% 67.33% 6.53 GB 13.46 GB 20 GB + E:\ Pagefile NTFS Fixed 98.75% 1.25% 9.87 GB 128.41 MB 10 GB + F:\ Unknown CDRom 0.00% 0.00% 0 B 0 B 0 B + + + Lists disk drive stats such as disk space,free used percent etc. + +NAME + Get-LongFreeDriveLetter + +SYNOPSIS + List free or available drive letters on the local machine + + Get-LongFreeDriveLetter [-Last] [] + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Get-LongFreeDriveLetter -Verbose + VERBOSE: Get-LongFreeDriveLetter: Listing the first free DriveLetter + G + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Get-LongFreeDriveLetter -Last -Verbose + VERBOSE: Get-LongFreeDriveLetter: Listing the Last free DriveLetter + Z + + + + +NAME + Get-LongItem + +SYNOPSIS + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Get-LongItem C:\temp + + + This command gets the 'fileinfo' for the directory C:\temp. The object that is retrieved represents only the directory, not its contents. + +NAME + Get-LongMappedDrive + +SYNOPSIS + List mapped drives + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Get-LongMappedDrive | fl * + + UncPath : \\Contoso\Share1\ + DriveLetter : H:\ + FileSystem : NTFS + FreePercent : 11.61% + UsedPercent : 88.39% + Free : 5.79 GB + Used : 44.11 GB + Size : 49.9 GB + AvailableFreeSpace : 6217994240 + DriveFormat : NTFS + DriveType : Network + IsReady : True + Name : H:\ + RootDirectory : H:\ + TotalFreeSpace : 6217994240 + TotalSize : 53580132352 + VolumeLabel : + DiskSpaceInfo : H:\ + DosDeviceName : H: + IsDosDeviceSubstitute : False + IsUnc : True + IsVolume : True + VolumeInfo : + + + Lists any mapped drives on the local machine + +NAME + Mount-LongShare + +SYNOPSIS + Maps network drive + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Mount-LongShare -DriveLetter Z: -NetWorkShare \\contoso\share1 -Verbose + + + Maps the network share named share1 to the local drive Z: + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Mount-LongShare -DriveLetter F: -NetWorkShare \\contoso\share1 -Credential (Get-Credential) + + + the credential parameter is used to pass alternate credentials to access the network share "share1" and map it to drive F: + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\>$cred = Get-Credential + Mount-LongShare -DriveLetter G: -NetWorkShare \\contoso\share1 -Credential $cred + + + the get-credential cmdlet is used to store credentials in the variable 'cred' + the cred variable is then passed to the credential parameter in Mount-LongShare to map Share1 to Drive G: + +NAME + Move-LongItem + +SYNOPSIS + Move file\folders + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Move-LongItem -path C:\temp\test.txt -destination C:\Temp\folder1\tst.txt + + + This command moves the Test.txt file from the C:\temp to the C:\Temp\folder1 directory and renames it from "test.txt" to "tst.txt". + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Move-LongItem -Path C:\temp\logfiles -Destination C:\temp\newlogfiles + + + This command moves the C:\Temp\logfiles directory and its contents to the C:\temp\newLogfiles directory. The logfiles directory, and all of its subdirectories and files, then appear in the newLogfiles directory. + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\>Get-LongChildItem -Path C:\temp -Filter *.csv -Recurse | Move-longItem -Destination C:\temp\logs -Verbose + + + This command moves all of the csv files from the c:\temp directory and all subdirectories, recursively, to the C:\temp\logs directory. + + The command uses the Get-LongChildItem cmdlet to get all of the child items in the temp directory and its subdirectories that have a *.csv file name extension. It uses the Recurse parameter to make the retrieval + recursive and the filter parameter to limit the retrieval to *.csv files. + + The pipeline operator (|) sends the results of this command to Move-LongItem, which moves the csv files to the logs directory. + + If files being moved to C:\temp\logs have the same name, Move-LongItem displays an warning and continues, but it moves only one file with each name to C:\temp\logs. The other files remain in their original + directories. + + If the logs directory (or any other element of the destination path) does not exist, the command fails. The missing directory is not created for you, even if you use the Force parameter. + +NAME + New-LongItem + +SYNOPSIS + Creates new file,folder,symboliclink or hardlink items. + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>New-Longitem -path c:\temp -name logfiles -itemtype directory + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>New-LongItem -ItemType File -path 'c:\temp\test.txt', 'c:\temp\logs\test.log' + + + This command uses the New-LongItem cmdlet to create files in two different directories. Because the Path parameter takes multiple strings, you can use it to create multiple items. + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\>New-LongItem -Path C:\temp\123\456\hello.txt -Verbose + + + The New-LongItem cmdlet is used to create the directory tree '123'\'456' which dosent exist and then finally a text file 'hello.txt' inside the '456' directory. + -------------------------- EXAMPLE 4 -------------------------- + + PS C:\>New-LongItem -Path c:\temp\test.txt -ItemType File -Force -Value "1st Line","2nd Line" -Encoding UTF8 + + + Create a text file named test.txt and write 2 lines separated by a line break with UTF8 encoding. + -------------------------- EXAMPLE 5 -------------------------- + + PS C:\>New-LongItem -Name test -ItemType Directory + + + a directory named test is created in the current working directory + -------------------------- EXAMPLE 6 -------------------------- + + PS C:\>New-LongItem -Name c:\temp\test.txt + + + we use the name parameter instead of path to create a text file named test. + -------------------------- EXAMPLE 7 -------------------------- + + PS C:\>New-LongItem -Path C:\temp\MySymlink.txt -Value C:\temp\test.txt -ItemType SymbolicLink + + + a symbolic link named mysymlink.txt is created for an existing file named test located at c:\temp + -------------------------- EXAMPLE 8 -------------------------- + + PS C:\>New-LongItem -Name MySymlink -Value C:\temp -ItemType SymbolicLink -Force + + + a symboliclink named mysymlink is created for c:\temp in the current directory. + Note: since the -Force switch is used any existing symlink named mysymlink will be overwritten. + -------------------------- EXAMPLE 9 -------------------------- + + PS C:\>New-LongItem -Path C:\temp\MyHardlink.txt -Value C:\temp\test.txt -ItemType HardLink + + + a hardlink named myhardlink is created for the existing file at c:\temp\test.txt + +NAME + Remove-LongItem + +SYNOPSIS + Deletes specified item. + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Remove-LongItem -Path C:\temp\folder3\drivers.txt -force + + + This command deletes a file that is read-only. It uses the Path parameter to specify the file. It uses the Force parameter to give permission to delete it. Without Force, you cannot delete read-only files. + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Remove-LongItem -path C:\temp\folder7\filenames -Recurse + + + This command deletes the folder 'filenames' including all files and sub-folders. + +NAME + Rename-LongItem + +SYNOPSIS + Renames an item in a AlphaFS FileSystem provider namespace. + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\>Rename-LongItem -path C:\temp\drivers.txt -NewName d1.txt -Verbose -Confirm:$false + + + This command renames the file drivers.txt to d1.txt + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\>Get-LongChildItem -Path C:\temp\drivers.txt | + Rename-LongItem -NewName {'prefix' + $_.basename + 'Suffix' + $_.extension } + + + the file 'drivers.txt' is renamed by piping the output of 'Get-LongChildItem' to Rename-LongItem. The newfilename is created by adding a prefix and a suffix to the filename resulting in the following newname: + 'PrefixdriversSuffix.txt'. + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\>Get-ChildItem -Path C:\temp -Filter *.txt | Rename-LongItem -NewExtension log -Confirm:$false + + VERBOSE: Performing the operation "Changing Extension" on target "Item: C:\temp\d1.txt Destination: C:\temp\d1.log". + VERBOSE: Rename-LongItem: + C:\temp\d1.txt + C:\temp\d1.log + + VERBOSE: Performing the operation "Changing Extension" on target "Item: C:\temp\d2.txt Destination: C:\temp\d2.log". + VERBOSE: Rename-LongItem: + C:\temp\d2.txt + C:\temp\d2.log + + + This command gets all the text files in c:\temp and pipes them to Rename-LongItem which then renames each text file extension from *.txt to *.log + Note: the name os the file is retained(in other words remains unchanged) diff --git a/Helpers/PSAlphaFSHelpers.ps1 b/Helpers/PSAlphaFSHelpers.ps1 new file mode 100644 index 0000000..afbbb15 --- /dev/null +++ b/Helpers/PSAlphaFSHelpers.ps1 @@ -0,0 +1,470 @@ +Function GetDotNetVer { + #https://gallery.technet.microsoft.com/scriptcenter/Detect-NET-Framework-120ec923 + #modified to work with this module + [cmdletbinding()] + param() + $dotNetRegistry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP' + $dotNet4Registry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' + $dotNet4Builds = + @{ + 30319 = '4.0' + 378389 = '4.5' + 378675 = '4.5.1' + 378758 = '4.5.1' + 379893 = '4.5.2' + 380042 = '4.5' + 393295 = '4.6' + 393297 = '4.6' + 394254 = '4.6.1' + 394271 = '4.6.1' + 394802 = '4.6.2' + 394806 = '4.6.2' + } + + + + if($regKey = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Default')) + { + if ($netRegKey = $regKey.OpenSubKey($dotNetRegistry)) { + foreach ($versionKeyName in $netRegKey.GetSubKeyNames()) + { + if ($versionKeyName -match '^v[123]') + { + $versionKey = $netRegKey.OpenSubKey($versionKeyName) + $version = [version]($versionKey.GetValue('Version', '')) + '{0}.{1}' -f $version.Major,$version.minor + } + } + } + + if ($net4RegKey = $regKey.OpenSubKey($dotNet4Registry)) + { + if(-not ($net4Release = $net4RegKey.GetValue('Release'))) + { + $net4Release = 30319 + } + $dotNet4Builds[$net4Release] + + } + }#open reg key + + + }#end function + + +$installed_dotnetversion = GetDotNetVer -ErrorAction SilentlyContinue | sort -Descending | Select-Object -First 1 +$libpath_parent = join-path (Split-Path $PSScriptRoot -Parent) -ChildPath lib + +if([string]::IsNullOrEmpty($installed_dotnetversion)) +{ + $libpath = Join-Path $libpath_parent -ChildPath 'net40\AlphaFS.dll' +} +else +{ + switch($installed_dotnetversion) + { + '3.5' {$libpath = Join-Path $libpath_parent -ChildPath 'net35\AlphaFS.dll';break} + '4.0' {$libpath = Join-Path $libpath_parent -ChildPath 'net40\AlphaFS.dll';break} + '4.5.0' {$libpath = Join-Path $libpath_parent -ChildPath 'net45\AlphaFS.dll';break} + '4.5.1' {$libpath = Join-Path $libpath_parent -ChildPath 'net451\AlphaFS.dll';break} + '4.5.2' {$libpath = Join-Path $libpath_parent -ChildPath 'net452\AlphaFS.dll';break} + '4.6.1' {$libpath = Join-Path $libpath_parent -ChildPath 'net452\AlphaFS.dll';break} + '4.6.2' {$libpath = Join-Path $libpath_parent -ChildPath 'net452\AlphaFS.dll';break} + default {$libpath = Join-Path $libpath_parent -ChildPath 'net40\AlphaFS.dll'} + } + +}# if installed_dotnetversion + + +# Load the AlphaFS assembly +Add-Type -Path $libpath + + +#Define Alphafs Class Shortcuts +$DirObject = [Alphaleonis.Win32.Filesystem.Directory] +$FileObject = [Alphaleonis.Win32.Filesystem.File] +$FileinfoObject = [Alphaleonis.Win32.Filesystem.FileInfo] +$PathFSObject = [Alphaleonis.Win32.Filesystem.Path] +$PathFSFormatObject = [Alphaleonis.Win32.Filesystem.PathFormat] +$dirEnumOptionsFSObject = [Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions] +$copyFsObject = [Alphaleonis.Win32.Filesystem.CopyOptions] +$linktype = [Alphaleonis.Win32.Filesystem.SymbolicLinkTarget] +$MoveOptions = [Alphaleonis.Win32.Filesystem.MoveOptions] + + +Function FormatDriveLetter ([string]$DriveLetter) +{ + #Format driveletter + if($DriveLetter -notmatch '[aA-zZ]:\\') + { + $DriveLetter = "$DriveLetter`:\" + } + return $DriveLetter +} + +Function CheckMappedDriveExists ([string]$DriveLetter, [String]$NetworkShare) +{ + + $DriveLetterFormatted = FormatDriveLetter $DriveLetter + $isDrivePresent = [Alphaleonis.Win32.Filesystem.DriveInfo]::GetDrives() | Where-Object { ($_.DriveType -eq 'Network') -and ($_.DriveLetter -eq $DriveLetterFormatted) -and ($_.UncPath -eq $NetworkShare) } + if ($isDrivePresent) + { + Write-Verbose "MappedDrive ['$DriveLetterFormatted'] for NetworkShare ['$NetworkShare'] exists." + return $true + } + else + { + Write-Verbose "MappedDrive ['$DriveLetterFormatted'] for NetworkShare ['$NetworkShare'] does not exist." + return $false + } +} + + +# function to match file extensions +function CompareExtension([string[]]$Extension, $Filename) +{ + foreach ($p in $Extension) + { + $wc = New-Object System.Management.Automation.WildcardPattern -ArgumentList ($p, [System.Management.Automation.WildcardOptions]::IgnoreCase) + if ($wc.IsMatch($Filename)) {return $true} + } + +} + + + +Function newlongitemhelper { + #[cmdletbinding()] + param + ( + [string]$Filename, + [String]$itemtype, + $value, + [String]$Encoding, + [Switch]$Force + ) + + + $FilePath = $Filename + $Leaf = $PathFSObject::GetFileName($FilePath) + $Parent = $PathFSObject::GetDirectoryName($FilePath) + $isFile = if($PathFSObject::HasExtension($Leaf) ){$true}else {$false} + + + + # Create the parent + if (-not ($DirObject::Exists($Parent)) ) + { + $DirObject::CreateDirectory($Parent) | Out-Null + } + + if($ItemType -eq 'File') + { + # check if there is an existing folder with the same name as the file we are trying to create + if($DirObject::Exists($FilePath)) + { + Write-Warning ("New-LongItem: A Directory with the same name '{0}' already exists." -f $FilePath) + return + } + #Create a file + if($FileObject::Exists($FilePath)) + { + if($Force) + { + + if ($Value) + { + $FileObject::WriteAllLines($FilePath, $value, [System.Text.Encoding]::$Encoding, $PathFSFormatObject::FullPath) + } + Else + { + $FileObject::Create($FilePath, $PathFSFormatObject::FullPath) | Out-Null + } + + New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $FilePath, $PathFSFormatObject::FullPath + + } + Else + { + Write-Warning ("New-LongItem: The file '{0}' already exists. Use '-Force' to overwrite" -f $FilePath) + } + + }# file exists + Else + { + + if ($Value) + { + $FileObject::WriteAllLines($FilePath, $value, [System.Text.Encoding]::$Encoding, $PathFSFormatObject::FullPath) + } + Else + { + $FileObject::Create($FilePath, $PathFSFormatObject::FullPath) | Out-Null + } + + New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $FilePath, $PathFSFormatObject::FullPath + + + }# if file dosent exist + + }# if itemtype is file + Elseif($ItemType -eq 'Directory') + { + + if($FileObject::Exists($FilePath)) + { + Write-Warning ("New-LongItem: A file with the same name '{0}' already exists." -f $FilePath) + return + } + if($DirObject::Exists($FilePath)) + { + if($Force) + { + $DirObject::CreateDirectory($FilePath) + } + Else + { + Write-Warning ("New-LongItem: The Directory '{0}' already exists. Use '-Force' to overwrite" -f $FilePath) + } + + }# folder exists + Else + { + $DirObject::CreateDirectory($FilePath) + } + }# itemtype is directory + Elseif($ItemType -eq 'HardLink') + { + + if($Value) + { + + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($value)) + { + $value = $PathFSObject::Combine($PWD, $value.TrimStart('.\')) + } + + $ExistingFile_Leaf = $PathFSObject::GetFileName($value) + $ExistingFile_info = New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Value + $ExistingDirectory_info = New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo -ArgumentList $Value + + if(-not $ExistingFile_info.Exists) + { + if($ExistingDirectory_info.Exists) + { + Write-Warning ("New-LongItem: The Hardlink to be created cannot be a folder '{0}'" -f $FilePath) + return + } + Else + { + Write-warning ("New-LongItem:`tHardLink Link Target '{0}' does not exist" -f $Value) + return + + } + + }#if the target does not exist + + + if($FileObject::Exists($FilePath)) + { + if($Force) + { + $FileObject::Delete($FilePath, $true, $PathFSFormatObject::FullPath) + $FileObject::CreateHardlink($FilePath, $value) + } + Else + { + Write-Warning ("New-LongItem: The Hardlink '{0}' already exists. Use -Force to overwrite" -f $FilePath) + return + } + + + + }# file exists + else + { + Write-Verbose ("New-LongItem:`tCreating Symbolic Link ['{0}'] for ['{1}']" -f $FilePath,$Value) + $FileObject::CreateHardlink($FilePath, $value) + } + + } + Else + { + Write-Warning ("New-LongItem: Please provide the target for The Hardlink '{0}' " -f $FilePath) + + }# if no value is provided + + }# if Hardlink + + Elseif($ItemType -eq 'SymbolicLink') + { + + if($Value) + { + + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($value)) + { + $value = $PathFSObject::Combine($PWD, $value.TrimStart('.\')) + } + + $ExistingFile_Leaf = $PathFSObject::GetFileName($value) + $ExistingFile_info = New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Value + $ExistingDirectory_info = New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo -ArgumentList $Value + + if( (-not $ExistingFile_info.Exists) -and (-not $ExistingDirectory_info.Exists) ) + { + Write-warning ("New-LongItem:`tSymbolic Link Target '{0}' does not exist" -f $Value) + return + } + + $isFile_Real = if($ExistingFile_info.EntryInfo.IsDirectory){$false}else {$true} + + if($isFile_Real) + { + $linktarget = $linktype::File + + } + Else + { + $linktarget = $linktype::Directory + + } + + $checkfortarget_file = $FileObject::Exists($FilePath) + $checkfortarget_dir = $DirObject::Exists($FilePath) + + if($checkfortarget_file -or $checkfortarget_dir) + { + + if($Force) + { + try + { + $FileObject::Delete($FilePath, $true, $PathFSFormatObject::FullPath) + } + Catch + { + try + { + $DirObject::Delete($FilePath, $true, $PathFSFormatObject::FullPath) + } + catch + { + throw $_ + } + + } + $FileObject::CreateSymbolicLink($FilePath, $value, $linktarget) + } + Else + { + Write-Warning ("New-LongItem: The SymbolicLink '{0}' already exists.Use -Force to overwrite" -f $FilePath) + return + } + + }# file exists + else + { + Write-Verbose ("New-LongItem:`tCreating Symbolic Link ['{0}'] for ['{1}']" -f $FilePath,$Value) + $FileObject::CreateSymbolicLink($FilePath, $value, $linktarget) + } + + } + Else + { + Write-Warning ("New-LongItem: Please provide the target for The SymbolicLink '{0}' " -f $FilePath) + + }# if no value is provided + + + }# if itemtype is symboliclink + Else + { + #best effort to create a file or directory + if($isFile) + { + + # check if there is an existing folder with the same name as the file we are trying to create + if($DirObject::Exists($FilePath)) + { + Write-Warning ("New-LongItem: A Directory with the same name '{0}' already exists." -f $FilePath) + return + } + #Create a file + if($FileObject::Exists($FilePath)) + { + if($Force) + { + + if ($Value) + { + $FileObject::WriteAllLines($FilePath, $value, [System.Text.Encoding]::$Encoding, $PathFSFormatObject::FullPath) + } + Else + { + $FileObject::Create($FilePath, $PathFSFormatObject::FullPath) | Out-Null + } + + New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $FilePath, $PathFSFormatObject::FullPath + + } + Else + { + Write-Warning ("New-LongItem: The file '{0}' already exists. Use '-Force' to overwrite" -f $FilePath) + } + + }# file exists + Else + { + + if ($Value) + { + $FileObject::WriteAllLines($FilePath, $value, [System.Text.Encoding]::$Encoding, $PathFSFormatObject::FullPath) + } + Else + { + $FileObject::Create($FilePath, $PathFSFormatObject::FullPath) | Out-Null + } + + New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $FilePath, $PathFSFormatObject::FullPath + + + }# if file dosent exist + + }# if file + else + { + if($FileObject::Exists($FilePath)) + { + Write-Warning ("New-LongItem: A file with the same name '{0}' already exists." -f $FilePath) + return + } + if($DirObject::Exists($FilePath)) + { + if($Force) + { + $DirObject::CreateDirectory($FilePath) + } + Else + { + Write-Warning ("New-LongItem: The Directory '{0}' already exists. Use '-Force' to overwrite" -f $FilePath) + } + + }# folder exists + Else + { + $DirObject::CreateDirectory($FilePath) + } + + + }# if not file but a folder + + + }#if itemtype is not specified + + } + + + + + diff --git a/PSAlphaFS.psd1 b/PSAlphaFS.psd1 index 0bc4aec..e131f26 100644 Binary files a/PSAlphaFS.psd1 and b/PSAlphaFS.psd1 differ diff --git a/PSAlphaFS.psm1 b/PSAlphaFS.psm1 index dedf3b1..c12cc21 100644 --- a/PSAlphaFS.psm1 +++ b/PSAlphaFS.psm1 @@ -1,505 +1,202 @@ - # .ExternalHelp PSAlphafs.psm1-help.xml function Get-LongChildItem { - - [CmdletBinding(DefaultParameterSetName='All')] - Param - ( - # Specify the Path to the File or Folder - [ValidateScript({ - if( [Alphaleonis.Win32.Filesystem.Directory]::Exists($_) -or [Alphaleonis.Win32.Filesystem.File]::Exists($_) ) { $true} - Else{Write-warning ("Get-LongChildItem:`tPath '{0}' does not exist`n`n" -f $_) } - })] - [Parameter(Mandatory=$false, - ValueFromPipelineByPropertyName=$true, - ValueFromPipeline=$true, - Position=0)] - [String[]] - $Path = $PWD, + [Alias('ldir','lgci')] + [CmdletBinding(DefaultParameterSetName = 'All')] + Param + ( + # Specify the Path to the File or Folder + [Parameter(ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String[]] + $Path = $PWD, - # Filter wildcard string - [Parameter(Mandatory=$false,Position=1)] - [String] - $Filter = '*', - - # Enumerate Subdirectories - [Switch] - $Recurse, + # Filter wildcard string + [Parameter(Position = 1)] + [String] + $Filter = '*', + + # Enumerate Subdirectories + [Switch] + $Recurse, - # Multiple string names to exclude - [String[] ] - $Include, + # Multiple string names to exclude + [String[] ] + $Include, - # Multiple string names to include - [String[] ] - $Exclude, + # Multiple string names to include + [String[] ] + $Exclude, - # Get Only Folders - [Switch] - $Directory, + # Get Only Folders + [Switch] + $Directory, - # Get Only Files - [Switch] - $File, + # Get Only Files + [Switch] + $File, - # Get Only File or Folder Names - [Switch] - $Name + # Get Only File or Folder Names + [Switch] + $Name, + + # Dont show symbolic links + [Switch] + $SkipSymbolicLink - ) - - Begin - { - $DirObject = [Alphaleonis.Win32.Filesystem.Directory] + ) + + Begin + { + + $dirEnumOptions = $dirEnumOptionsFSObject::ContinueOnException + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::BasicSearch + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::LargeCache + + if($PSBoundParameters.Containskey('Recurse') ) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::Recursive + } + if($PSBoundParameters.Containskey('SkipSymbolicLink') ) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::SkipReparsePoints + } + if($PSBoundParameters.Containskey('Directory') -and (-not($PSBoundParameters.Containskey('File')))) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::Folders + } + if($PSBoundParameters.Containskey('file') -and (-not($PSBoundParameters.Containskey('Directory')))) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::Files + } + if(-not($PSBoundParameters.Containskey('Directory')) -and (-not($PSBoundParameters.ContainsKey('File')) )) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::FilesAndFolders + } + if($PSBoundParameters.Containskey('Directory') -and $PSBoundParameters.ContainsKey('File') ) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::FilesAndFolders + } + + $dirEnumOptions = [Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions]$dirEnumOptions + $privilegeEnabler = New-Object -TypeName Alphaleonis.Win32.Security.PrivilegeEnabler -ArgumentList ([Alphaleonis.Win32.Security.Privilege]::Backup, $null) - if($PSBoundParameters.Containskey('Include') ) - { - $Include | ForEach-Object {$Include_string += "`$_.Name -like '$_' -or " } - $Include_string = $Include_string -replace '-or\s$','' - } - if($PSBoundParameters.Containskey('Exclude') ) - { - $Exclude | ForEach-Object {$Exclude_string += "`$_.Name -notlike '$_' -and " } - $Exclude_string = $Exclude_string -replace '-and\s$','' - } - if($PSBoundParameters.Containskey('Include') -and $PSBoundParameters.ContainsKey('Exclude') ) - { - $Inc_Exc_String = '(' + $Include_string + ')' + ' -AND ' + '(' + $Exclude_string + ')' - } - if($PSBoundParameters.Containskey('Recurse') ) - { - $search_option = 'AllDirectories' - } - Else - { - $search_option = 'TopDirectoryOnly' - } - - $privilege = [Alphaleonis.Win32.Security.Privilege]::Backup - $privilegeEnabler = New-Object Alphaleonis.Win32.Security.PrivilegeEnabler($privilege) - - } - Process - { - foreach ($pItem in $Path) - { - - $PathObject = New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $pItem - $Attributes = ($PathObject.Attributes -split ',').trim() - - if($Attributes -contains 'Directory') - { - if ($Directory) - { - foreach ($N in @($DirObject::EnumerateDirectories($pItem ,$Filter, [System.IO.SearchOption]::$search_option) )) - { - if($Include -and (-not $Exclude) ) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) | - Select-Object -ExpandProperty Name - } - - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) - } - - - } - elseif($Exclude -and (-not $Include) ) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) | - Select-Object -ExpandProperty Name - } - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) - } - - } - Elseif($Include -and $Exclude) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) | - Select-Object -ExpandProperty Name - } - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) - } - - } - Else - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Select-Object -ExpandProperty Name - } - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N - - } - - }#if not include or exclude - - }#foreach file or folder - - }#if folder - Elseif($File) - { - foreach ($N in @($DirObject::EnumerateFiles($pItem ,$Filter, [System.IO.SearchOption]::$search_option) )) - { - if($Include -and (-not $Exclude) ) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) | - Select-Object -ExpandProperty Name - } - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) - } - - } - elseif($Exclude -and (-not $Include) ) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) | - Select-Object -ExpandProperty Name - } - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) - } - } - Elseif($Include -and $Exclude) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) | - Select-Object -ExpandProperty Name - } - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) - } - - } - Else - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Select-Object -ExpandProperty Name - } - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N - - } - } - }#foreach name - }#else file - Else - { - - foreach ($DirType in @('EnumerateDirectories','EnumerateFiles')) - { - - foreach ($N in @($DirObject::$DirType($pItem ,$Filter, [System.IO.SearchOption]::$search_option) ) ) - { - if($Include -and (-not $Exclude) ) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) | - Select-Object -ExpandProperty Name - } - - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Include_string) } $_ ) - } - - } - elseif($Exclude -and (-not $Include) ) - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) | - Select-Object -ExpandProperty Name - } - - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Exclude_string) } $_ ) - } - } - Elseif($Include -and $Exclude) - { - if($Name) - { - - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) | - Select-Object -ExpandProperty Name - } - - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Where-Object (& {[scriptblock]::create($Inc_Exc_String) } $_ ) - } - - } - Else - { - if($Name) - { - if($Recurse) - { - $newpath = $pItem -Replace '\\','\\' - - (New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Select-Object -ExpandProperty FullName ) -replace "$newpath\\" , '' - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N | - Select-Object -ExpandProperty Name - } - - } - Else - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $N - - } - - } - }#foreach name - - }#foreach file & folder - - }#else process both files & folders - - }#If path is a folder - Else - { - - if($Name) - { - $PathObject | Select-Object -ExpandProperty Name - } - Else - { - Write-Output -InputObject $PathObject - - } - - }#if path is not a folder - - }#foreach path item - }#Process - end - { - If ($privilegeEnabler) - { - $privilegeEnabler.Dispose() - } - }#end - + } + Process + { + foreach ($pItem in $Path) + { + # Check if path is relative + if(-not $PathFSObject::IsPathRooted($Path, $true)) + { + $pItem = $PathFSObject::Combine($PWD, $pItem.TrimStart('.\')) + } + + # Check if path exists on the filesystem + if(-not ($FileObject::Exists($pItem) -or $DirObject::Exists($pItem))) + { + Write-Warning -Message ("Get-LongChildItem:`tPath '{0}' dosent exist." -f $pItem) + continue + } + + $PathObject = New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $pItem, $PathFSFormatObject::FullPath + + if($PathObject.EntryInfo.IsDirectory) + { + $DirObject::EnumerateFileSystemEntries($pItem,$Filter,$dirEnumOptions) | + ForEach-Object -Process { + if ($Include -and (-not(CompareExtension -Extension $Include -Filename $PathFSObject::GetFileName($_)))) + { + return + } + if ($Exclude -and (CompareExtension -Extension $Exclude -Filename $PathFSObject::GetFileName($_))) + { + return + } + if($Name) + { + $_.Replace($pItem,'') -replace '^\\' + } + Else + { + New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $_, $PathFSFormatObject::FullPath + } + }#foreach filesystementry + }#If path is a folder + Else + { + if($Name) + { + $PathObject | Select-Object -ExpandProperty Name + } + Else + { + Write-Output -InputObject $PathObject + } + }#if path is not a folder + }#foreach path item + }#Process + end + { + If ($privilegeEnabler) + { + $privilegeEnabler.Dispose() + } + }#end }#End Function + # .ExternalHelp PSAlphafs.psm1-help.xml function Get-LongItem { - - [CmdletBinding()] - Param - ( - # Specify the Path to the File or Folder - [ValidateScript({ - if( [Alphaleonis.Win32.Filesystem.Directory]::Exists($_) -or [Alphaleonis.Win32.Filesystem.File]::Exists($_) ) { $true} - Else{Write-warning ("Get-LongItem:`tPath '{0}' does not exist`n`n" -f $_) } - })] - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - ValueFromPipeline=$true, - Position=0)] - [String[]] - $Path + [CmdletBinding()] + Param + ( + # Specify the Path to the File or Folder + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String[]] + $Path - ) - - Begin - { - $DirObject = [Alphaleonis.Win32.Filesystem.Directory] - $privilege = [Alphaleonis.Win32.Security.Privilege]::Backup - $privilegeEnabler = New-Object Alphaleonis.Win32.Security.PrivilegeEnabler($privilege) - } - Process - { - foreach ($PItem in $Path) - { - New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $PItem - } + ) + + Begin + { + $privilegeEnabler = New-Object -TypeName Alphaleonis.Win32.Security.PrivilegeEnabler -ArgumentList ([Alphaleonis.Win32.Security.Privilege]::Backup, $null) + } + Process + { + foreach ($pItem in $Path) + { + # Check if path is relative + if(-not $PathFSObject::IsPathRooted($Path, $true)) + { + $pItem = $PathFSObject::Combine($PWD, $pItem.TrimStart('.\')) + } + + # Check if path exists on the filesystem + if(-not ($FileObject::Exists($pItem) -or $DirObject::Exists($pItem))) + { + Write-Warning -Message ("Get-LongItem:`tPath '{0}' dosent exist." -f $pItem) + continue + } + + New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $pItem, $PathFSFormatObject::FullPath + } - }#Process - End - { - If ($privilegeEnabler) - { - $privilegeEnabler.Dispose() - } - }#end + }#Process + End + { + If ($privilegeEnabler) + { + $privilegeEnabler.Dispose() + } + }#end }#End Function @@ -507,633 +204,1203 @@ function Get-LongItem # .ExternalHelp PSAlphafs.psm1-help.xml function Rename-LongItem { - [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact = 'High')] - Param - ( - # The Path to the File or Folder - [ValidateScript({ - if( [Alphaleonis.Win32.Filesystem.Directory]::Exists($_) -or [Alphaleonis.Win32.Filesystem.File]::Exists($_) ) { $true} - Else{Write-warning ("Rename-LongItem:`tPath '{0}' does not exist`n`n" -f $_) } - })] - [Alias('FullName')] - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - ValueFromPipeline=$true, - Position=0)] - [String] - $Path, + [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'High',DefaultParameterSetName = 'Name')] + Param + ( + # The Path to the File or Folder + [Alias('FullName')] + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String] + $Path, - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - Position=1)] - [String] - $NewName, + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Name', + Position = 1)] + [String] + $NewName, + + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Extension', + Position = 1)] + [String] + $NewExtension, - [Switch] - $Force + #[parameter(ParameterSetName = 'Name')] + [Switch] + $Force - ) - - Begin - { - } - Process - { - $Parent = Split-Path -Path $Path -Parent - $NewPath = Join-Path -Path $Parent -ChildPath $NewName - $ReplaceExisting = [Alphaleonis.Win32.Filesystem.MoveOptions]::ReplaceExisting + ) + + Begin + { + $ReplaceExisting = $MoveOptions::ReplaceExisting + } + Process + { + + + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($Path)) + { + $Path = $PathFSObject::Combine($PWD, $Path.TrimStart('.\')) + } + + if(-not ($FileObject::Exists($Path) -or $DirObject::Exists($Path))) + { + Write-Warning -Message ("Rename-LongItem:`tPath '{0}' dosent exist." -f $Path) + return + } + + $PathObject = New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Path + + if($PathObject.EntryInfo.IsDirectory) + { + $isfile = $false + $fsObject = $DirObject + + }else + { + $isfile = $true + $fsObject = $FileObject + } + - if($PSCmdlet.ShouldProcess($NewPath,"Rename File: $Path") ) - { - if($Force) - { - Write-Verbose ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path,$NewPath) - [Alphaleonis.Win32.Filesystem.Directory]::Move($Path, $NewPath,$ReplaceExisting) - } - Else - { - if([Alphaleonis.Win32.Filesystem.Directory]::Exists($NewPath)) - { - Write-Warning ("Rename-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $NewPath) - } - Else - { - Write-Verbose ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path,$NewPath) - [Alphaleonis.Win32.Filesystem.Directory]::Move($Path, $NewPath) - } - - } - - } + if($PSCmdlet.ParameterSetName -eq 'Name' ) + { + + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($NewName)) + { + $NewPath = $PathFSObject::Combine($PWD, $NewName.TrimStart('.\')) + } + Else + { + $NewPath = $NewName + } + + if($Path -eq $NewPath) + { + Write-Warning ("Rename-LongItem:`t{0} and {1} are the same" -f $Path, $NewPath) + return + } + + if($isfile) + { + # check if there is an existing folder with the same name as the file we are trying to create + if($DirObject::Exists($NewPath)) + { + Write-Warning ("Rename-LongItem: A Directory with the same name '{0}' already exists." -f $NewPath) + return + } + #Create a file + if($FileObject::Exists($NewPath)) + { + if($Force) + { + + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $FileObject::Move($Path, $NewPath,$ReplaceExisting, $PathFSFormatObject::FullPath) + + } + Else + { + Write-Warning -Message ("Rename-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $NewPath) + } + + }# file exists + Else + { + if($PSCmdlet.ShouldProcess("Item:`t$path Destination:`t$NewName","Rename File")) + { + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $FileObject::Move($Path, $NewPath, $PathFSFormatObject::FullPath) + } + + } + } + # if path is a file + Else + { + # check if there is an existing folder with the same name as the file we are trying to create + if($FileObject::Exists($NewPath)) + { + Write-Warning ("Rename-LongItem: A File with the same name '{0}' already exists." -f $NewPath) + return + } + #Create a file + if($DirObject::Exists($NewPath)) + { + if($Force) + { + + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $DirObject::Move($Path, $NewPath,$ReplaceExisting, $PathFSFormatObject::FullPath) + + } + Else + { + Write-Warning -Message ("Rename-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $NewPath) + } + + }# file exists + Else + { + if($PSCmdlet.ShouldProcess("Item:`t$path Destination:`t$NewName","Rename File")) + { + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $DirObject::Move($Path, $NewPath, $PathFSFormatObject::FullPath) + } + } + # Directory + + } + } + #set + if($PSCmdlet.ParameterSetName -eq 'Extension' ) + { + $NewPath = $PathFSObject::ChangeExtension($Path, $NewExtension) + if($Path -eq $NewPath) + { + Write-Warning ("Rename-LongItem:`t{0} and {1} are the same" -f $Path, $NewPath) + return + } + + if($isfile) + { + # check if there is an existing folder with the same name as the file we are trying to create + if($DirObject::Exists($NewPath)) + { + Write-Warning ("New-LongItem: A Directory with the same name '{0}' already exists." -f $NewPath) + return + } + #Create a file + if($FileObject::Exists($NewPath)) + { + if($Force) + { + + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $FileObject::Move($Path, $NewPath,$ReplaceExisting, $PathFSFormatObject::FullPath) + + } + Else + { + Write-Warning -Message ("Rename-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $NewPath) + } + + }# file exists + Else + { + if($PSCmdlet.ShouldProcess("Item:`t$Path`tDestination:`t$($PathFSObject::ChangeExtension($Path, $NewExtension))",'Changing Extension')) + { + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $FileObject::Move($Path, $NewPath, $PathFSFormatObject::FullPath) + } + + } + } + # if path is a file + Else + { + # check if there is an existing folder with the same name as the file we are trying to create + if($FileObject::Exists($NewPath)) + { + Write-Warning ("New-LongItem: A File with the same name '{0}' already exists." -f $NewPath) + return + } + #Create a file + if($DirObject::Exists($NewPath)) + { + if($Force) + { + + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $DirObject::Move($Path, $NewPath,$ReplaceExisting, $PathFSFormatObject::FullPath) + + } + Else + { + Write-Warning -Message ("Rename-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $NewPath) + } + + }# file exists + Else + { + if($PSCmdlet.ShouldProcess("Item:`t$Path`tDestination:`t$($PathFSObject::ChangeExtension($Path, $NewExtension))",'Changing Extension')) + { + Write-Verbose -Message ("Rename-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $DirObject::Move($Path, $NewPath, $PathFSFormatObject::FullPath) + } + } + # Directory + + } + + + + } + #set Extension - }#Process - End - { + }#Process + End + { - } - + } }#end function # .ExternalHelp PSAlphafs.psm1-help.xml function Copy-LongItem { - [CmdletBinding()] - Param - ( - # The Path to the File or Folder - [ValidateScript({ - if( [Alphaleonis.Win32.Filesystem.Directory]::Exists($_) -or [Alphaleonis.Win32.Filesystem.File]::Exists($_) ) { $true} - Else{Write-warning ("Copy-LongItem:`tPath '{0}' does not exist`n`n" -f $_) } - })] - [Alias('FullName')] - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - ValueFromPipeline=$true, - Position=0)] - [String] - $Path, + [CmdletBinding()] + Param + ( + # The Path to the File or Folder + [Alias('FullName')] + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String] + $Path, - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - Position=1)] - [String] - $Destination, - - [Switch] - $Force - ) - - Begin - { - $DirObject = [Alphaleonis.Win32.Filesystem.Directory] - $FileObject = [Alphaleonis.Win32.Filesystem.File] - $copyOptions = [Alphaleonis.Win32.Filesystem.CopyOptions]::FailIfExists - } - Process - { - $PathObject = New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Path - $Attributes = ($PathObject.Attributes -split ',').trim() + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + Position = 1)] + [String] + $Destination, - $basename = Split-Path -Path $Path -Leaf - $dBasename = Split-Path -Path $Destination -Leaf - $dParent = Split-Path -Path $Destination -Parent + [Switch] + $Force, + + # If the source file is a symbolic link, + # the destination file is also a symbolic link pointing to the same file that the source symbolic link is pointing to. + #[Switch] + #$CopySymbolicLink, + + # The copy operation is performed using unbuffered I/O, bypassing system I/O cache resources. Recommended for very large file transfers. + [Switch] + $NoBuffering, + + # An attempt to copy an encrypted file will succeed even if the destination copy cannot be encrypted. + [Switch] + $AllowDecryptedDestination + ) + + Begin + { + $copyOptions = $copyFsObject::FailIfExists + if($PSBoundParameters.Containskey('CopySymbolicLink') ) + { + $copyOptions = $copyOptions -bor $copyFsObject::CopySymbolicLink + } + if($PSBoundParameters.Containskey('NoBuffering') ) + { + $copyOptions = $copyOptions -bor $copyFsObject::NoBuffering + } + if($PSBoundParameters.Containskey('AllowDecryptedDestination') ) + { + $copyOptions = $copyOptions -bor $copyFsObject::AllowDecryptedDestination + } + $copyOptions = [Alphaleonis.Win32.Filesystem.CopyOptions]$copyOptions + $privilegeEnabler = New-Object -TypeName Alphaleonis.Win32.Security.PrivilegeEnabler -ArgumentList ([Alphaleonis.Win32.Security.Privilege]::CreateSymbolicLink, $null) + } + Process + { + + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($Path,$true)) + { + $Path = $PathFSObject::Combine($PWD, $Path.TrimStart('.\')) + } + + if(-not ($FileObject::Exists($Path) -or $DirObject::Exists($Path))) + { + Write-Warning -Message ("Copy-LongItem:`tPath '{0}' dosent exist." -f $Path) + return + } + + $PathObject = New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Path, $PathFSFormatObject::FullPath + $basename = $PathFSObject::GetFileName($Path) + $dBasename = $PathFSObject::GetFileName($Destination) + $dParent = $PathFSObject::GetDirectoryName($Destination) + $dBasenameObj = New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $dBasename + $isFile = if($PathFSObject::HasExtension($dBasename) ) + { + $true + } + else + { + $false + } - if($dBasename -match '.*\.\w{2,4}$') - { - $Destination_isFile = $true - if( -not ( $DirObject::Exists($dParent))) - { - $DirObject::CreateDirectory($dParent) | Out-Null - } - - }#destination is a file - Else - { - $Destination_isDirectory = $true - if( -not ( $DirObject::Exists($Destination))) - { - $DirObject::CreateDirectory($Destination) | Out-Null - } - Else - { - $Destination = Join-Path -Path $Destination -ChildPath $basename - } - - }#destination is a folder + # Create the directory tree before the copy + if($isFile) + { + $Destination_isFile = $true + if( -not ( $DirObject::Exists($dParent))) + { + $null = $DirObject::CreateDirectory($dParent) + } + }#destination is a file + Else + { + $Destination_isDirectory = $true + if( -not ( $DirObject::Exists($Destination))) + { + $null = $DirObject::CreateDirectory($Destination) + } + Else + { + $Destination = $PathFSObject::Combine($Destination, $basename) + } + }#destination is a folder - - - - if($Force){$Overwrite = $true}else{$Overwrite = $false } - - if($Attributes -contains 'Directory') - { - - $Destination = - try - { - $DirObject::Copy($Path, $destination,$copyOptions) - } - catch [Alphaleonis.Win32.Filesystem.AlreadyExistsException] - { - if($Force) - { - Write-Verbose ("Copy-LongItem:`t Overwriting existing directory...Copying '{0}' to '{1}'" -f $Path,$Destination) - $DirObject::Copy($Path, $Destination, $Overwrite) - } - Else - { - Write-Warning ("Copy-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $Destination) - } - - } - Catch - { - throw $_ - } + + if($PathObject.EntryInfo.IsDirectory) + { + $fsObject = $DirObject + } + else + { + $fsObject = $FileObject + } + + # Perform the copy + try + { + Write-Verbose -Message ("Copy-LongItem:`tCopying '{0}' to '{1}'" -f $Path, $Destination) + $fsObject::Copy($Path, $Destination,$copyOptions) + } + catch [Alphaleonis.Win32.Filesystem.AlreadyExistsException] + { + if($Force) + { + # need to delete destination because the copy method dosent contain an overload that includes + # both the overwrite and copyoptions parameters + $DirObject::Delete($Destination, $true, $true, $PathFSFormatObject::FullPath) + + Write-Verbose -Message ("Copy-LongItem:`t Overwriting existing item...Copying '{0}' to '{1}'" -f $Path, $Destination) + $fsObject::Copy($Path, $Destination, $copyOptions) + } + Else + { + Write-Warning -Message ("Copy-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $Destination) + } + } + Catch + { + throw $_ + } - }#Directory - Else - { - try - { - $FileObject::Copy($Path, $destination, $copyOptions) - } - catch [Alphaleonis.Win32.Filesystem.AlreadyExistsException] - { - if($Force) - { - Write-Verbose ("Copy-LongItem:`t Overwriting existing File...Copying '{0}' to '{1}'" -f $Path,$Destination) - $FileObject::Copy($Path, $Destination, $Overwrite) - } - Else - { - Write-Warning ("Copy-LongItem:`tAn item with the same name already exists at '{0}'.`nUse '-Force' to overwrite" -f $Destination) - } - - } - Catch - { - throw $_ - } - - }#file - - - }#Process - End - { - - } + + }#Process + End + { + If ($privilegeEnabler) + { + $privilegeEnabler.Dispose() + } + } }#end function # .ExternalHelp PSAlphafs.psm1-help.xml function Remove-LongItem { - [CmdletBinding()] - Param - ( - # The Path to the File or Folder - [ValidateScript({ - if( [Alphaleonis.Win32.Filesystem.Directory]::Exists($_) -or [Alphaleonis.Win32.Filesystem.File]::Exists($_) ) { $true} - Else{Write-warning ("Remove-LongItem:`tPath '{0}' does not exist`n`n" -f $_) } - })] - [Alias('FullName')] - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - ValueFromPipeline=$true, - Position=0)] - [String] - $Path, + [CmdletBinding()] + Param + ( + # The Path to the File or Folder + [Alias('FullName')] + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String] + $Path, - [Switch] - $Recurse, + [Switch] + $Recurse, - [Switch] - $Force - ) - - Begin - { - $DirObject = [Alphaleonis.Win32.Filesystem.Directory] - $FileObject = [Alphaleonis.Win32.Filesystem.File] - $DirOptions = [Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions]::FilesAndFolders - $privilege = [Alphaleonis.Win32.Security.Privilege]::Backup - $privilegeEnabler = New-Object Alphaleonis.Win32.Security.PrivilegeEnabler($privilege) + [Switch] + $Force + ) + + Begin + { + + $DirOptions = $dirEnumOptionsFSObject::FilesAndFolders + $privilegeEnabler = New-Object -TypeName Alphaleonis.Win32.Security.PrivilegeEnabler -ArgumentList ([Alphaleonis.Win32.Security.Privilege]::Backup, $null) - } - Process - { - $PathObject = New-Object Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Path - $Attributes = ($PathObject.Attributes -split ',').trim() + } + Process + { + + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($Path,$true)) + { + $Path = $PathFSObject::Combine($PWD, $Path.TrimStart('.\')) + } + + if(-not ($FileObject::Exists($Path) -or $DirObject::Exists($Path))) + { + Write-Warning -Message ("Remove-LongItem:`tPath '{0}' dosent exist." -f $Path) + return + } + + $PathObject = New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Path + - if($Recurse){$RemoveAll = $true;$Force = $true}else{$RemoveAll = $false } - if($Force){$IgnoreReadOnly = $true}else{$IgnoreReadOnly = $false } - - if($Attributes -contains 'Directory') - { - if($Recurse) - { - Write-Verbose ("Remove-LongItem:`t Deleting directory '{0}' recursively" -f $Path) - $DirObject::Delete($Path, $RemoveAll, $IgnoreReadOnly) - } - Else - { - if( $DirObject::CountFileSystemObjects($path,$DirOptions) -gt 0) - { - Write-Warning ("Remove-LongItem:`t The Directory '{0}' is not Empty.`nUse '-Recurse' to remove it." -f $Path) - } - Else - { - Write-Verbose ("Remove-LongItem:`t Deleting empty directory '{0}'" -f $Path) - $DirObject::Delete($Path, $RemoveAll, $IgnoreReadOnly) - } + if($Recurse) + { + $RemoveAll = $true + $Force = $true + } + else + { + $RemoveAll = $false + } + if($Force) + { + $IgnoreReadOnly = $true + } + else + { + $IgnoreReadOnly = $false + } + if($PathObject.EntryInfo.IsDirectory) + { + if($Recurse) + { + Write-Verbose -Message ("Remove-LongItem:`t Deleting directory '{0}' recursively" -f $Path) + $DirObject::Delete($Path, $RemoveAll, $IgnoreReadOnly, $PathFSFormatObject::FullPath) + } + Else + { + if( $DirObject::CountFileSystemObjects($Path,$DirOptions) -gt 0) + { + Write-Warning -Message ("Remove-LongItem:`t The Directory '{0}' is not Empty.`nUse '-Recurse' to remove it." -f $Path) + } + Else + { + Write-Verbose -Message ("Remove-LongItem:`t Deleting empty directory '{0}'" -f $Path) + $DirObject::Delete($Path, $RemoveAll, $IgnoreReadOnly, $PathFSFormatObject::FullPath) + } + }#if not recurse + } + Else + { + try + { + Write-Verbose -Message ("Remove-LongItem:`t Deleting file '{0}'..." -f $Path) + $FileObject::Delete($Path, $IgnoreReadOnly, $PathFSFormatObject::FullPath) + } + catch [Alphaleonis.Win32.Filesystem.FileReadOnlyException] + { + Write-Warning -Message ("Remove-LongItem:`t The file '{0}' is ReadOnly.`nUse '-Force' to remove it." -f $Path) + } + catch + { + throw $_ + } + }#If file - }#if not recurse - - } - Else - { - try - { - Write-Verbose ("Remove-LongItem:`t Deleting file '{0}'..." -f $Path) - $FileObject::Delete($Path, $IgnoreReadOnly) - } - catch [Alphaleonis.Win32.Filesystem.FileReadOnlyException] - { - Write-Warning ("Remove-LongItem:`t The file '{0}' is ReadOnly.`nUse '-Force' to remove it." -f $Path) - } - catch - { - throw $_ - } - - - }#If file - - - }#Process - End - { - If ($privilegeEnabler) - { - $privilegeEnabler.Dispose() - } - } + }#Process + End + { + If ($privilegeEnabler) + { + $privilegeEnabler.Dispose() + } + } }#end function # .ExternalHelp PSAlphafs.psm1-help.xml function New-LongItem { - [CmdletBinding(DefaultParameterSetName = 'Path')] - Param - ( - # The Path to the File or Folder - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - ValueFromPipeline=$true,ParameterSetName = 'Path', - Position=0)] - [String[]] - [Parameter(ParameterSetName = 'Name',Mandatory = $false)] - $Path = $pwd, + [CmdletBinding(DefaultParameterSetName = 'Path')] + Param + ( + # The Path to the File or Folder + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline,ParameterSetName = 'Path', + Position = 0)] + [String[]] + [Parameter(ParameterSetName = 'Name')] + $Path, - [ValidateSet('Directory','File')] - [String] - $ItemType, - - [Parameter(Mandatory=$true,ParameterSetName = 'Name')] - [String] - $Name, + + [Alias('Type')] + [ValidateSet('Directory','File','SymbolicLink','HardLink')] + [String] + $ItemType, + + [Alias('Target')] + [Parameter()] + $Value, + + [ValidateSet('ASCII','BigEndianUnicode','Unicode','UTF32','UTF7','UTF8')] + [Parameter()] + [String] + $Encoding = 'Default', + + [Alias('LinkName')] + [Parameter(Mandatory,ParameterSetName = 'Name')] + [String] + $Name, - [Switch] - $Force - ) + [Switch] + $Force + ) + + Begin + { + + $privilegeEnabler = New-Object -TypeName Alphaleonis.Win32.Security.PrivilegeEnabler -ArgumentList ([Alphaleonis.Win32.Security.Privilege]::CreateSymbolicLink, $null) + + } + Process + { + + if($Path) + { + foreach ($pItem in $Path) + { + if($PSCmdlet.ParameterSetName -eq 'Path') + { + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($pItem)) + { + $pItem = $PathFSObject::Combine($PWD, $pItem) + } + + $FilePath = $pItem + }# pscmdlet Path + + if($PSCmdlet.ParameterSetName -eq 'Name') + { + if($PathFSObject::IsPathRooted($Name) -and $PathFSObject::IsPathRooted($pItem)) + { + Write-Warning -Message ("New-LongItem: The given path's format is not supported") + break + } + + + elseif([Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($pItem)) + { + $FilePath = $PathFSObject::Combine($pItem, $Name) + } + Else + { + $FilePath = $PathFSObject::Combine($PWD, $pItem, $Name) + } + }#pscmdlet is Name + + + $params = + @{ + Filename = $FilePath + itemtype = $ItemType + value = $Value + Encoding = $Encoding + } + if($Force) {$params.Add('Force',$Force)} + newlongitemhelper @params + + + }#foreach pitem + }# if path + Else + { + if($PSCmdlet.ParameterSetName -eq 'Name') + { + if([Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($Name)) + { + $FilePath = $Name + } + Else + { + $FilePath = $PathFSObject::Combine($PWD, $Name) + } + }#pscmdlet is Name + + $params = + @{ + Filename = $FilePath + itemtype = $ItemType + value = $Value + Encoding = $Encoding + } + if($Force) {$params.Add('Force',$Force)} + newlongitemhelper @params + }# if path is not specified + + }#Process + End + { + If ($privilegeEnabler) + { + $privilegeEnabler.Dispose() + } + } +}#end function - Begin - { - $DirObject = [Alphaleonis.Win32.Filesystem.Directory] - $FileObject = [Alphaleonis.Win32.Filesystem.File] - $FileinfoObject = [Alphaleonis.Win32.Filesystem.FileInfo] - } - Process - { +# .ExternalHelp PSAlphafs.psm1-help.xml +function Move-LongItem +{ + [CmdletBinding()] + Param + ( + # The Path to the File or Folder + [ValidateScript({ + if( [Alphaleonis.Win32.Filesystem.Directory]::Exists($_) -or [Alphaleonis.Win32.Filesystem.File]::Exists($_) ) + { + $true + } + Else + { + Write-Warning -Message ("Rename-LongItem:`tPath '{0}' does not exist`n`n" -f $_) + } + })] + [Alias('FullName')] + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String] + $Path, + + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + Position = 1)] + [String] + $Destination, - foreach ($pItem in $Path) - { - $Baseobj = Split-Path -Path $pItem -Leaf - $Parent = Split-Path -Path $pItem -Parent - $isFile = [regex]::Match($Baseobj , '\.\w{2,4}$') | Select-Object -ExpandProperty Success + [Switch] + $Force - if($PSCmdlet.ParameterSetName -eq 'Path') - { - - if( ($ItemType -eq 'File') -or ($isFile) ) - { - $FilePath = $pItem - - if (-not ($DirObject::Exists($Parent)) ) - { - $DirObject::CreateDirectory($Parent) - } - - if($FileObject::Exists($FilePath)) - { - if($Force) - { - $FileObject::Create($FilePath) | Out-Null - $FileinfoObject::new($FilePath) - } - Else - { - Write-Warning ("New-LongItem: The file '{0}' already exists. Use '-Force' to overwrite" -f $FilePath) - } - - }# file exists - Else - { - $FileObject::Create($FilePath) | Out-Null - $FileinfoObject::new($FilePath) - } - - }#isFile - Elseif( ($ItemType -eq 'Directory') -or (-not $isFile) ) - { - $FolderPath = $pItem - - if($DirObject::Exists($FolderPath)) - { - if($Force) - { - $DirObject::CreateDirectory($FolderPath) - } - Else - { - Write-Warning ("New-LongItem: The Directory '{0}' already exists. Use '-Force' to overwrite" -f $FolderPath) - } - - }# folder exists - Else - { - $DirObject::CreateDirectory($FolderPath) - } - - - }# if directory - - }#pscmdlet is path + + ) + + Begin + { + $ReplaceExisting = [Alphaleonis.Win32.Filesystem.MoveOptions]::ReplaceExisting + } + Process + { + $Parent = $PathFSObject::GetDirectoryName($Path) + $basename = $PathFSObject::GetFileName($Path) + $dParent = $PathFSObject::GetDirectoryName($Destination) + $dBasename = $PathFSObject::GetFileName($Destination) + + $isFile = if($PathFSObject::HasExtension($basename) ) + { + $true + } + else + { + $false + } + $isFile_destination = if($PathFSObject::HasExtension($dBasename) ) + { + $true + } + else + { + $false + } - if($PSCmdlet.ParameterSetName -eq 'Name') - { - - if($ItemType -eq 'File') - { - $FilePath = Join-Path -Path $pItem -ChildPath $Name - - if (-not ($DirObject::Exists($Parent)) ) - { - $DirObject::CreateDirectory($Parent) - } - - if($FileObject::Exists($FilePath)) - { - if($Force) - { - $FileObject::Create($FilePath) | Out-Null - $FileinfoObject::new($FilePath) - } - Else - { - Write-Warning ("New-LongItem: The file '{0}' already exists. Use '-Force' to overwrite" -f $FilePath) - } - - }# file exists - Else - { - $FileObject::Create($FilePath) | Out-Null - $FileinfoObject::new($FilePath) - } - - }#isFile - Elseif($ItemType -eq 'Directory') - { - $FolderPath = Join-Path -Path $pItem -ChildPath $Name - - if($DirObject::Exists($FolderPath)) - { - if($Force) - { - $DirObject::CreateDirectory($FolderPath) - } - Else - { - Write-Warning ("New-LongItem: The Directory '{0}' already exists. Use '-Force' to overwrite" -f $FolderPath) - } + if($isFile) + { + #Basename is a file so destination has to be a file + $Basename_isFile = $true - }# folder exists - Else - { - $DirObject::CreateDirectory($FolderPath) - } - - - }# if directory - - }#pscmdlet is Name + if ($isFile_destination) + { + $Destination_isFile = $true + $NewPath = $Destination + } + Else + { + $Destination_isDirectory = $true + $NewPath = $PathFSObject::Combine($Destination, $basename) + } + }#basename is file + Else + { + #basename is a folder so check the destination basename + $Basename_isDirectory = $true + if ($isFile_destination) + { + Write-Warning -Message ("Move-LongItem:`tThe source is a directory so please specify a directory as the destination") + break + } + Else + { + $Destination_isDirectory = $true + + if($DirObject::Exists($Destination )) + { + $NewPath = $PathFSObject::Combine($Destination, $basename) + } + Else + { + $NewPath = $Destination + } + }# destination is a directory + }#basename is a directory - }#foreach pitem - - }#Process - End - { - - } + if($Path -ne $NewPath) + { + if ($Basename_isFile) + { + $Object = $FileObject + } + Elseif($Basename_isDirectory) + { + $Object = $DirectoryObject + } + + if($Force) + { + Write-Verbose -Message ("Move-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $Object::Move($Path, $NewPath,$ReplaceExisting) + } + Else + { + try + { + Write-Verbose -Message ("Move-LongItem:`n {0} `n`t`t{1}`n" -f $Path, $NewPath) + $Object::move($Path,$NewPath) + } + catch [Alphaleonis.Win32.Filesystem.AlreadyExistsException] + { + Write-Warning -Message ("Move-LongItem:`tAn item named '{0}' already exists at the destination.`nUse '-Force' to overwrite" -f $NewPath) + } + Catch + { + throw $_ + } + }#no force + } + Else + { + Write-Warning -Message ("Move-LongItem:`tAn item cannot be moved to a destination that is same as the source") + } + + + + }#Process + End + { + + } }#end function - # .ExternalHelp PSAlphafs.psm1-help.xml -function Move-LongItem +function Mount-LongShare { - [CmdletBinding()] - Param - ( - # The Path to the File or Folder - [ValidateScript({ - if( [Alphaleonis.Win32.Filesystem.Directory]::Exists($_) -or [Alphaleonis.Win32.Filesystem.File]::Exists($_) ) { $true} - Else{Write-warning ("Rename-LongItem:`tPath '{0}' does not exist`n`n" -f $_) } - })] - [Alias('FullName')] - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - ValueFromPipeline=$true, - Position=0)] - [String] - $Path, - - [Parameter(Mandatory=$true, - ValueFromPipelineByPropertyName=$true, - Position=1)] - [String] - $Destination, - - [Switch] - $Force - + [CmdletBinding(DefaultParameterSetName = 'Simple')] + Param + ( + # Specify the Local Drive the NetworkShare is to be Mapped to + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + Position = 0)] + [String] + $DriveLetter, + + # Specify the NetworkShare that is to be mapped + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + Position = 1)] + [String] + $NetWorkShare, + + # Specify the NetworkShare that is to be mapped + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ParameterSetName = 'Credential', + Position = 2)] + [pscredential] + $Credential + + + - ) - - Begin - { - $ReplaceExisting = [Alphaleonis.Win32.Filesystem.MoveOptions]::ReplaceExisting - $FileObject = [Alphaleonis.Win32.Filesystem.File] - $DirectoryObject = [Alphaleonis.Win32.Filesystem.Directory] - } - Process - { - $Parent = Split-Path -Path $Path -Parent - $basename = Split-Path -Path $Path -Leaf - $dParent = Split-Path -Path $Destination -Parent - $dBasename = Split-Path -Path $Destination -Leaf + ) + + Begin + { + + } + Process + { + $DriveLetter = FormatDriveLetter $DriveLetter + + if(-not (Test-Path $DriveLetter)) + { + + if(-not (CheckMappedDriveExists $DriveLetter $NetworkShare)) + { + + if($PSCmdlet.ParameterSetName -eq 'Credential') + { + $NetWorkCreds = New-Object -TypeName System.Net.NetworkCredential -ArgumentList @($Credential.UserName, $Credential.Password) + $Domain = $Credential.GetNetworkCredential().domain + + if($Domain) + { + $NetWorkCreds.Domain = $Domain + } + + #map drive + try + { + Write-Verbose -Message ("Mount-LongShare:`t Mapping NetWorkShare ['{0}'] to DriveLetter ['{1}'] with Credentials '[{2}']" -f $NetWorkShare, $DriveLetter, $Credential.UserName) + $MapDrive = [Alphaleonis.Win32.Network.Host]::ConnectDrive($DriveLetter, $NetWorkShare, $Credential, $false, $true, $true) + } + catch + { + throw $_ + } + }# Parameterset Credential + + if($PSCmdlet.ParameterSetName -eq 'Simple') + { + #map drive + try + { + Write-Verbose -Message ("Mount-LongShare:`t Mapping NetWorkShare ['{0}'] to DriveLetter ['{1}']" -f $NetWorkShare, $DriveLetter) + $MapDrive = [Alphaleonis.Win32.Network.Host]::ConnectDrive($DriveLetter, $NetWorkShare) + } + catch + { + throw $_ + } + }# Parameterset Simple + + }# check if share is already mapped + else + { + Write-Warning -Message ("Mount-LongShare:`t The Drive ['{0}'] is already mapped to share ['{1}']" -f $DriveLetter, $NetWorkShare) + } + } + else + { + Write-Warning -Message ("Mount-LongShare:`t The Drive ['{0}'] is in use" -f $DriveLetter) + } + - if($Basename -match '\.\w{2,4}$') - { - #Basename is a file so destination has to be a file - $Basename_isFile = $true - - if ($dBasename -match '\.\w{2,4}$') - { - $Destination_isFile = $true - $NewPath = $Destination - } - Else - { - $Destination_isDirectory = $true - $NewPath = Join-Path -Path $Destination -ChildPath $basename - } - }#basename is file - Else - { - #basename is a folder so check the destination basename - $Basename_isDirectory = $true - if ($dBasename -match '\.\w{2,4}$') - { - Write-Warning ("Move-LongItem:`tThe source is a directory so please specify a directory as the destination") - break - - } - Else - { - - $Destination_isDirectory = $true - - if($DirectoryObject::Exists($Destination )) - { - $NewPath = Join-Path -Path $Destination -ChildPath $basename - } - Else - { - $NewPath = $Destination - } - - - - } - + }#Process + End + { + + }#end +}#End Function +# .ExternalHelp PSAlphafs.psm1-help.xml +function DisMount-LongShare +{ + [CmdletBinding()] + Param + ( + # Specify the Local Drive the NetworkShare is to be Mapped to + [Parameter(Mandatory, + ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String] + $DriveLetter, + + # Specify if the existing Connections to a share are to be closed + [Switch] + $Force + + ) + + Begin + { + + } + Process + { + + $DriveLetter = FormatDriveLetter $DriveLetter + if( -not (Test-path $DriveLetter )) + { + Write-warning ("DisMount-LongShare:`tPath '{0}' does not exist`n`n" -f $DriveLetter) + return + } + + + #map drive + try + { + if($Force) + { + Write-Verbose -Message ("DisMount-LongShare:`t Force Detected...Closing open network connections and Removing Mapped Drive ['{0}']" -f $DriveLetter) + $RemoveDrive = [Alphaleonis.Win32.Network.Host]::DisconnectDrive($DriveLetter, $true, $true) + } + Else + { + Write-Verbose -Message ("DisMount-LongShare:`t Removing Mapped Drive ['{0}']" -f $DriveLetter) + $RemoveDrive = [Alphaleonis.Win32.Network.Host]::DisconnectDrive($DriveLetter, $false, $true) + } + } + catch + { + if($_.Exception.InnerException -match 'This network connection has files open or requests pending') + { + throw 'This network connection has files open or requests pending...use the "-Force" switch to close existing connections without warning' + } + else + { + throw $_ + } + } + + + }#Process + End + { + + }#end +}#End Function - }#basename is a directory +# .ExternalHelp PSAlphafs.psm1-help.xml +function Get-LongMappedDrive +{ + [CmdletBinding()] + Param + ( + ) + + Begin + { + + } + Process + { + + #map drive + try + { + [Alphaleonis.Win32.Filesystem.DriveInfo]::GetDrives() | Where-Object -Property DriveType -EQ -Value 'Network' + } + catch + { + throw $_ + } + + + }#Process + End + { + + }#end +}#End Function + +# .ExternalHelp PSAlphafs.psm1-help.xml +function Get-LongFreeDriveLetter +{ + [CmdletBinding(DefaultParameterSetName = 'First')] + Param + ( + # get the last available drive letter. + [Parameter(ParameterSetName = 'Last')] + [Switch] + $Last + ) + + Begin + { + + } + Process + { + + if($PSCmdlet.ParameterSetName -eq 'First') + { + #map drive + try + { + Write-Verbose -Message ("Get-LongFreeDriveLetter:`t Listing the first free DriveLetter") + [Alphaleonis.Win32.Filesystem.DriveInfo]::GetFreeDriveLetter() + } + catch + { + throw $_ + } + }# Parameterset First + + if($PSCmdlet.ParameterSetName -eq 'Last') + { + #map drive + try + { + Write-Verbose -Message ("Get-LongFreeDriveLetter:`t Listing the Last free DriveLetter") + [Alphaleonis.Win32.Filesystem.DriveInfo]::GetFreeDriveLetter($true) + } + catch + { + throw $_ + } + }# Parameterset Last + + + }#Process + End + { + }#end +}#End Function - if($Path -ne $NewPath) - { - - if ($Basename_isFile) - { - $Object = $FileObject - } - Elseif($Basename_isDirectory) - { - $Object = $DirectoryObject - } - - if($Force) - { - Write-Verbose ("Move-LongItem:`n {0} `n`t`t{1}`n" -f $Path,$NewPath) - $Object::Move($Path, $NewPath,$ReplaceExisting) - } - Else - { +# .ExternalHelp PSAlphafs.psm1-help.xml +function Get-LongDiskDrive +{ + [CmdletBinding()] + Param + ( + ) + + Begin + { + + } + Process + { + + #List drive + try + { + [Alphaleonis.Win32.Filesystem.DriveInfo]::GetDrives() + } + catch + { + throw $_ + } + + + + }#Process + End + { + + }#end +}#End Function + +# .ExternalHelp PSAlphafs.psm1-help.xml +function Get-LongDirectorySize +{ + [CmdletBinding()] + Param + ( + # Specify the Path to a Folder + [Parameter( + ValueFromPipelineByPropertyName, + ValueFromPipeline, + Position = 0)] + [String] + $Path = $pwd, + + # Enumerate Subdirectories + [Switch] + $Recurse, + + # Enumerate Subdirectories + [Switch] + $ContinueonError + + ) + + Begin + { + $privilegeEnabler = New-Object -TypeName Alphaleonis.Win32.Security.PrivilegeEnabler -ArgumentList ([Alphaleonis.Win32.Security.Privilege]::Backup, $null) + $dirEnumOptions = $dirEnumOptionsFSObject::SkipReparsePoints + + if($PSBoundParameters.Containskey('Recurse') ) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::Recursive + } + if($PSBoundParameters.Containskey('ContinueonError') ) + { + $dirEnumOptions = $dirEnumOptions -bor $dirEnumOptionsFSObject::ContinueOnException + } + $dirEnumOptions = [Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions]$dirEnumOptions + } + Process + { + + if(-not [Alphaleonis.Win32.Filesystem.Path]::IsPathRooted($Path)) + { + $Path = $PathFSObject::Combine($PWD, $Path.TrimStart('.\')) + } + + if(-not $DirObject::Exists($Path)) + { + Write-Warning -Message ("Get-LongDirectorySize:`tPath '{0}' either is not a directory or it dosent exist." -f $Path) + return + } + + $PathObject = New-Object -TypeName Alphaleonis.Win32.Filesystem.FileInfo -ArgumentList $Path + + if(-not $PathObject.EntryInfo.IsDirectory) + { + Write-Warning -Message ("Get-LongDirectorySize:`tPlease prove a directory name as input to the path {0} parameter" -f $Path) + return + + } + + + $ResultHash = $DirObject::GetProperties( $Path, $dirEnumOptions, $PathFSFormatObject::FullPath) + $size = $ResultHash.Size - try - { - Write-Verbose ("Move-LongItem:`n {0} `n`t`t{1}`n" -f $Path,$NewPath) - $Object::move($path,$NewPath) - } - catch [Alphaleonis.Win32.Filesystem.AlreadyExistsException] - { - Write-Warning ("Move-LongItem:`tAn item named '{0}' already exists at the destination.`nUse '-Force' to overwrite" -f $NewPath) - } - Catch - { - throw $_ - } + if($size) + { + $postfixes = @( 'Bytes', 'KB', 'MB', 'GB', 'TB', 'PB' ) + for ($i = 0; $size -ge 1024 -and $i -lt $postfixes.Length - 1; $i++) + { + $size = $size / 1024 + } + $rounded_size = [Math]::Round($size,2) + $null = $ResultHash.Add("Sizein$($postfixes[$i])", $rounded_size) + Write-Verbose -Message ("The size of the folder '{0}' is '{1} {2}'" -f $Path, $rounded_size, $postfixes[$i]) + } + Write-Output -InputObject $ResultHash + + - }#no force - } - Else - { - Write-Warning ("Move-LongItem:`tAn item cannot be moved to a destination that is same as the source") - } - - - }#Process - End - { - - } - -}#end function + }#Process + End + { + If ($privilegeEnabler) + { + $privilegeEnabler.Dispose() + } + }#end +}#End Function -Set-Alias -Name ldir -Value Get-LongChildItem -Set-Alias -Name lgci -Value Get-LongChildItem \ No newline at end of file +Set-Alias -Name ldir -Value Get-LongChildItem \ No newline at end of file diff --git a/README.md b/README.md index 64a98bb..d50bd3a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ PSAlphaFS is a wrapper for the ALphaFS .NET library providing useful powerShell * Move-Item +## Version +Version 2.0.0.0 see [ChangeLog](https://github.com/v2kiran/PSAlphaFS/blob/master/Changelog.md) + ## Installation You have 2 choices: @@ -36,6 +39,9 @@ All cmdlets come with built-in help. To see sample usage of a cmdlet, just type: Get-Help Get-LongChildItem -Examples ``` +you can also see the list of exmaples here: [Examples](https://github.com/v2kiran/PSAlphaFS/blob/master/Examples.md) + + ## About PSAlphaFS ### Maximum Path Length Limitation @@ -55,6 +61,15 @@ The cmdlets in this module have been prefixed with the word "long" to distinguis * Remove-LongItem * New-LongItem +New in version 2.0 +* DisMount-LongShare +* Get-LongDirectorySize +* Get-LongDiskDrive +* Get-LongFreeDriveLetter +* Get-LongMappedDrive +* Mount-LongShare + + Links: @@ -62,6 +77,10 @@ Links: [AlphaFS](https://github.com/alphaleonis/AlphaFS) +[Examples](https://github.com/v2kiran/PSAlphaFS/blob/master/Examples.md) + +[ChangeLog](https://github.com/v2kiran/PSAlphaFS/blob/master/Changelog.md) + ## Note diff --git a/TypeData/PSAlphaFS.Format.ps1xml b/TypeData/PSAlphaFS.Format.ps1xml index 7922020..3cd4885 100644 --- a/TypeData/PSAlphaFS.Format.ps1xml +++ b/TypeData/PSAlphaFS.Format.ps1xml @@ -1,23 +1,29 @@ - - - AlphaFSFileSystemTypes - - Alphaleonis.Win32.Filesystem.FileInfo - Alphaleonis.Win32.Filesystem.FileSystemInfo - - - + + + AlphaFSFileSystemTypes + + Alphaleonis.Win32.Filesystem.FileInfo + Alphaleonis.Win32.Filesystem.FileSystemInfo + + + + AlphaFSFileSystemDriveTypes + + Alphaleonis.Win32.Filesystem.DriveInfo + + + children AlphaFSFileSystemTypes - - Directory - - + + Directory + + @@ -42,14 +48,34 @@ - - if ( ($_.Attributes -split ',').trim().contains('Directory') ){'Directory'}Else{'File'} - + + if ( $_.EntryInfo.IsDirectory ) + { + if ( $_.EntryInfo.IsSymbolicLink ) + { + return 'SymLink-d' + } + Else + { + return 'Directory' + } + } + Else + { + if ( $_.EntryInfo.IsSymbolicLink ) + { + return 'SymLink-f' + } + Else + { + return 'File' + } + } + + - - [String]::Format("{0,10} {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t")) - + [String]::Format("{0,10} {1,8}", $_.LastWriteTime.ToString("d"), $_.LastWriteTime.ToString("t")) Length @@ -61,6 +87,177 @@ - + + + DriveInfoTableView + + AlphaFSFileSystemDriveTypes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name + + + VolumeLabel + + + DriveFormat + + + DriveType + + + Right + + return ($_.DiskSpaceInfo.AvailableFreeSpacePercent) + + + + Right + + return ($_.DiskSpaceInfo.UsedSpacePercent) + + + + Right + + return ($_.DiskSpaceInfo.AvailableFreeSpaceUnitSize) + + + + Right + + return ($_.DiskSpaceInfo.UsedSpaceUnitSize) + + + + Right + + return ($_.DiskSpaceInfo.TotalSizeUnitSize) + + + + + + + + + DriveInfoListView + + AlphaFSFileSystemDriveTypes + + + + + + + + + return ($_.Name) + + + + VolumeLabel + + + + + return ($_.DriveFormat) + + + + DriveType + + + + + return ($_.TotalFreeSpace) + + + + + + return ($_.TotalSize) + + + + DosDeviceName + + + IsUnc + + + IsVolume + + + VolumeInfo + + + + + return ($_.DiskSpaceInfo.ClusterSize) + + + + + + return ($_.DiskSpaceInfo.BytesPerSector) + + + + + + return ($_.DiskSpaceInfo.NumberOfFreeClusters) + + + + + + return ($_.DiskSpaceInfo.SectorsPerCluster) + + + + + + return ($_.DiskSpaceInfo.TotalNumberOfClusters) + + + + + + + - + \ No newline at end of file diff --git a/TypeData/PSAlphaFS.Types.ps1xml b/TypeData/PSAlphaFS.Types.ps1xml index 6b7e6b8..be6a5ba 100644 --- a/TypeData/PSAlphaFS.Types.ps1xml +++ b/TypeData/PSAlphaFS.Types.ps1xml @@ -1,40 +1,154 @@ - - - Alphaleonis.Win32.Filesystem.FileInfo + + + Alphaleonis.Win32.Filesystem.FileInfo - - Mode - - if ( ($this.Attributes -split ',').trim().contains('Directory') ){'Directory'}Else{'File'} - - - - PathLength - - if ( ($this.Attributes -split ',').trim().contains('Directory') ){''}Else{$this.FullName.Length} - - - - BaseName - - if ($this.Extension.Length -gt 0){$this.Name.Remove($this.Name.Length - $this.Extension.Length)}else{$this.Name} - - - - PSStandardMembers - - - DefaultDisplayPropertySet - - Mode - LastWriteTime - Length - Name - - - - + + Mode + if ( $this.EntryInfo.IsDirectory ) { if ( $this.EntryInfo.IsSymbolicLink ){ return 'SymLink-d' } Else { return 'Directory' } } Else { if ( $this.EntryInfo.IsSymbolicLink ) { return 'SymLink-f' } Else { return 'File' } } + + + PSIsContainer + $this.EntryInfo.IsDirectory + + + LinkType + $s = $this.EntryInfo.ReparsePointTag ; switch($s){'Symlink' {return 'SymbolicLink';break};default {return $s}} + + + BaseName + [Alphaleonis.Win32.Filesystem.Path]::GetFileNameWithoutExtension($this.Name) + + + PathLength + $this.FullName.Length + + + IsLongPath + $this.EntryInfo.IsLongPath + + + IsSymbolicLink + $this.EntryInfo.IsSymbolicLink + + + IsDirectory + $this.EntryInfo.IsDirectory + + + IsCompressed + $this.EntryInfo.IsCompressed + + + IsHidden + $this.EntryInfo.IsHidden + + + IsEncrypted + $this.EntryInfo.IsEncrypted + + + IsMountPoint + $this.EntryInfo.IsMountPoint + + + IsOffline + $this.EntryInfo.IsOffline + + + FileHash + + if(-not ($this.EntryInfo.IsDirectory)) + { + return ($this.GetHash([Alphaleonis.Win32.Security.HashType]::SHA256)) + } + + + + Target + + if($this.EntryInfo.IsSymbolicLink) + { + return (([Alphaleonis.Win32.Filesystem.File]::GetLinkTargetInfo($this.FullName, [Alphaleonis.Win32.Filesystem.PathFormat]::FullPath)).PrintName) + } + + + + PSStandardMembers + + + DefaultDisplayPropertySet + + Mode + LastWriteTime + Length + Name + + + + - + + + Alphaleonis.Win32.Filesystem.DriveInfo + + + DriveLetter + Name + + + FileSystem + DriveFormat + + + FreePercent + return ($this.DiskSpaceInfo.AvailableFreeSpacePercent) + + + UsedPercent + return ($this.DiskSpaceInfo.UsedSpacePercent) + + + Free + return ($this.DiskSpaceInfo.AvailableFreeSpaceUnitSize) + + + Used + return ($this.DiskSpaceInfo.UsedSpaceUnitSize) + + + Size + return ($this.DiskSpaceInfo.TotalSizeUnitSize) + + + UncPath + + if($this.DriveType -eq 'Network') + { + return ([Alphaleonis.Win32.Filesystem.Path]::LocalToUnc([Alphaleonis.Win32.Filesystem.Path]::RemoveTrailingDirectorySeparator($this.Name))) + } + + + + Driveinfolistview + + + DefaultDisplayPropertySet + + DriveLetter + VolumeLabel + FileSystem + DriveType + FreePercent + UsedPercent + Free + Used + Size + UncPath + + + + + + \ No newline at end of file diff --git a/en-US/PSAlphaFS.psm1-Help.xml b/en-US/PSAlphaFS.psm1-Help.xml index bf1b08e..79b8dca 100644 --- a/en-US/PSAlphaFS.psm1-Help.xml +++ b/en-US/PSAlphaFS.psm1-Help.xml @@ -1,49 +1,59 @@ - - + + + - Copy-LongItem + Get-LongDirectorySize - + Gets the properties of a directory without following any symbolic links or mount points. - Copy - LongItem + Get + LongDirectorySize - hello + Properties include aggregated info from FileAttributes of each encountered file system object, plus additional ones: Total, File, Size and Error. +Total: is the total number of enumerated objects. +File: is the total number of files. File is considered when object is neither Directory nor ReparsePoint. +Size: is the total size(bytes) of enumerated objects. +Error: is the total number of errors encountered during enumeration. +Note: Reparsepoint count will always be 0 because they are skipped by default. - Copy-LongItem + Get-LongDirectorySize Path - Specifies the path to the items to copy. + The target directory.This value can be a relative or an aboslute path String - None + CurrentDirectory - - Destination + + Recurse - Specifies the path to the new location. To rename a copied item, include the new name in the value. + Enumerates files and folders in sub-directories - String - None + SwitchParameter + - Force + ContinueonError - Allows the cmdlet to copy items that cannot otherwise be changed, such as copying over an existing file or directory. + Suppress any Exception that might be thrown as a result from a failure, such as ACLs protected directories or non-accessible reparse points. +Note: using this switch might result in an incorrect directory size. SwitchParameter @@ -55,31 +65,32 @@ Path - Specifies the path to the items to copy. + The target directory.This value can be a relative or an aboslute path String String - None + CurrentDirectory - - Destination + + Recurse - Specifies the path to the new location. To rename a copied item, include the new name in the value. + Enumerates files and folders in sub-directories - String + SwitchParameter - String + SwitchParameter - None + - Force + ContinueonError - Allows the cmdlet to copy items that cannot otherwise be changed, such as copying over an existing file or directory. + Suppress any Exception that might be thrown as a result from a failure, such as ACLs protected directories or non-accessible reparse points. +Note: using this switch might result in an incorrect directory size. SwitchParameter @@ -105,23 +116,15 @@ - - This cmdlet does not return any output. - - None + Hashtable + + + - - Copy-LongItem - - - Copy-LongItem is like the 'cp' or 'copy' commands in other shells. -By default the recurse flag is set so a folder copy operation is always recursive. - - @@ -129,11 +132,33 @@ By default the recurse flag is set so a folder copy operation is always recursiv PS C:\> - Copy-LongItem -Path C:\temp\drivers.txt -Destination C:\temp\folder1 -Verbose - - This command copies the drivers.txt file to the C:\temp\folder1 directory. 'folder1' is created if it dosent exist. + Get-LongDirectorySize -Path D:\Github -Recurse - +Key Value +--- ----- +Archive 321 +Compressed 0 +Device 0 +Directory 201 +Encrypted 0 +Hidden 1 +IntegrityStream 0 +Normal 0 +NoScrubData 0 +NotContentIndexed 0 +Offline 0 +ReadOnly 264 +ReparsePoint 0 +SparseFile 0 +System 0 +Temporary 0 +File 321 +Total 522 +Size 3069696 +SizeinMB 3 + + + Gets the directory statistics for D:\Github, optionally enumerating the subfolders and files. @@ -141,9 +166,32 @@ By default the recurse flag is set so a folder copy operation is always recursiv PS C:\> - Copy-LongItem C:\temp\logfiles -Destination C:\temp\newlogs + Get-LongDirectorySize -ContinueonError - This command copies the contents of the C:\Logfiles directory recursively to the C:\temp\newLogs directory. It creates the \newLogs subdirectory if it does not already exist. + Enumerates the files and folders in the current directory, and will ignore any exceptions\errors that may arise due to access or other issues. +Warning: using the -ContinueonError may result in an incorrect directory size. + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + $githubDIR = Get-LongDirectorySize D:\Github -Recurse + +$githubDIR.Size +3069696 + +$githubDIR.SizeinMB +3 + +PS C:\temp\dsc> + + The first command assigns the out of the cmdlet Get-LongDirectorySize to the variable github +the second command is used to access the size of the directory in bytes. +the third command lists the size in megabytes. + +Note: the unit of size kb\mb\gb\tb will change based on the size of the directory. @@ -151,156 +199,65 @@ By default the recurse flag is set so a folder copy operation is always recursiv - Get-LongChildItem + Remove-LongItem - Gets the items and child items in one or more specified locations. + Deletes specified item. - Get - LongChildItem + Remove + LongItem - The Get-LongChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers. + The Remove-LongItem cmdlet deletes filesystem items. - Get-LongChildItem - + Remove-LongItem + Path - Specifies a path to one or more locations. Wildcards are NOT permitted. The default location is the current directory. - - String[] - current directory - - - Filter - - The value of this parameter qualifies the Path parameter. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved. + Specifies a path to the items being removed. Wildcards are NOT permitted. The parameter name ("-Path") is optional. - String - None + String - + Recurse - Gets the items in the specified locations and in all child items of the locations. - - SwitchParameter - false - - - Include - - Gets only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. - - String[] - None - - - Exclude - - Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. - - String[] - None - - - Directory - - Gets only the container items in the locations omitting all files. - - SwitchParameter - - - - File - - Gets only the file items in the locations omitting all container items. + Deletes the items in the specified locations and in all child items of the locations. SwitchParameter - None - - Name + + Force - Gets only the names of the items in the locations. If you pipe the output of this command to another command, only the item names are sent. + Allows the cmdlet to remove items that cannot otherwise be changed, such as read-only files. SwitchParameter - None - + Path - Specifies a path to one or more locations. Wildcards are NOT permitted. The default location is the current directory. - - String[] - - String - - - current directory - - - Filter - - The value of this parameter qualifies the Path parameter. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved. + Specifies a path to the items being removed. Wildcards are NOT permitted. The parameter name ("-Path") is optional. - String + String String - None + - + Recurse - Gets the items in the specified locations and in all child items of the locations. - - SwitchParameter - - SwitchParameter - - - false - - - Include - - Gets only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. - - String[] - - String[] - - - None - - - Exclude - - Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. - - String[] - - String[] - - - None - - - Directory - - Gets only the container items in the locations omitting all files. + Deletes the items in the specified locations and in all child items of the locations. SwitchParameter @@ -309,104 +266,1247 @@ By default the recurse flag is set so a folder copy operation is always recursiv - - File - - Gets only the file items in the locations omitting all container items. - - SwitchParameter - - SwitchParameter - - - None - - - Name + + Force - Gets only the names of the items in the locations. If you pipe the output of this command to another command, only the item names are sent. + Allows the cmdlet to remove items that cannot otherwise be changed, such as read-only files. SwitchParameter SwitchParameter - None + - - You can pipe a string that contains a path to Get-LongChildItem. - - System.String - + System.String + + + + + + - - For more information see: -http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm - - Alphaleonis.Win32.Filesystem.FileInfo - http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm + None + - - - If you use the Name parameter, Get-ChildItem returns the object names as strings. + This cmdlet does not return any output. + + - - System.String - - + - - You can also refer to Get-LongChildItem by its built-in aliases "ldir", and "lgci". For more information, see about_Aliases. - -Get-LongChildItem gets hidden items by default. - -The Get-LongChildItem cmdlet is designed to work with the data exposed by the AlphaFS Filesystem provider and will NOT work with any other providers E.g.,Registry,Certificates etc - -For more information, see (http://alphafs.alphaleonis.com/doc/2.0/api/html/7C1374.htm). + - + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Remove-LongItem -Path C:\temp\folder3\drivers.txt -force + + This command deletes a file that is read-only. It uses the Path parameter to specify the file. It uses the Force parameter to give permission to delete it. Without Force, you cannot delete read-only files. + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\> + + Remove-LongItem -path C:\temp\folder7\filenames -Recurse + + This command deletes the folder 'filenames' including all files and sub-folders. + + + + + + + + Move-LongItem + + Move file\folders + + + + + Move + LongItem + + + + Moves an item from one location to another. + + + + + Move-LongItem + + Path + + Specifies the path to the current location of the item.Wildcards are NOT permitted. + + String + + + Destination + + Specifies the path to the location where the items are being moved. + + String + + + Force + + Allows the cmdlet to move an item that writes over an existing read-only item + + SwitchParameter + + + + + + + Path + + Specifies the path to the current location of the item.Wildcards are NOT permitted. + + String + + String + + + + + + Destination + + Specifies the path to the location where the items are being moved. + + String + + String + + + + + + Force + + Allows the cmdlet to move an item that writes over an existing read-only item + + SwitchParameter + + SwitchParameter + + + + + + + + + + System.String + + + + + + + + + + + + + + + None + + + + This cmdlet does not return any output. + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Move-LongItem -path C:\temp\test.txt -destination C:\Temp\folder1\tst.txt + + This command moves the Test.txt file from the C:\temp to the C:\Temp\folder1 directory and renames it from "test.txt" to "tst.txt". + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\> + + Move-LongItem -Path C:\temp\logfiles -Destination C:\temp\newlogfiles + + This command moves the C:\Temp\logfiles directory and its contents to the C:\temp\newLogfiles directory. The logfiles directory, and all of its subdirectories and files, then appear in the newLogfiles directory. + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + Get-LongChildItem -Path C:\temp -Filter *.csv -Recurse | Move-longItem -Destination C:\temp\logs -Verbose + + This command moves all of the csv files from the c:\temp directory and all subdirectories, recursively, to the C:\temp\logs directory. + +The command uses the Get-LongChildItem cmdlet to get all of the child items in the temp directory and its subdirectories that have a *.csv file name extension. It uses the Recurse parameter to make the retrieval recursive and the filter parameter to limit the retrieval to *.csv files. + +The pipeline operator (|) sends the results of this command to Move-LongItem, which moves the csv files to the logs directory. + +If files being moved to C:\temp\logs have the same name, Move-LongItem displays an warning and continues, but it moves only one file with each name to C:\temp\logs. The other files remain in their original directories. + +If the logs directory (or any other element of the destination path) does not exist, the command fails. The missing directory is not created for you, even if you use the Force parameter. + + + + + + + + Mount-LongShare + + Maps network drive + + + + + Mount + LongShare + + + + Map a network share to a local drive + + + + + Mount-LongShare + + DriveLetter + + The name of a local device\drive to be redirected, such as "F:". +Note: you may omit the ':' in the drive letter, e.g. F + + String + + + + NetWorkShare + + The network resource to connect to. The string can be up to MAX_PATH characters in length. + + String + + + + + Mount-LongShare + + DriveLetter + + The name of a local device\drive to be redirected, such as "F:". +Note: you may omit the ':' in the drive letter, e.g. F + + String + + + + NetWorkShare + + The network resource to connect to. The string can be up to MAX_PATH characters in length. + + String + + + + Credential + + An instance of PSCredential which provides credentials for password-based authentication used to gain access to network resources that are restricted. + + PSCredential + + + + + + + + DriveLetter + + The name of a local device\drive to be redirected, such as "F:". +Note: you may omit the ':' in the drive letter, e.g. F + + String + + String + + + + + + NetWorkShare + + The network resource to connect to. The string can be up to MAX_PATH characters in length. + + String + + String + + + + + + Credential + + An instance of PSCredential which provides credentials for password-based authentication used to gain access to network resources that are restricted. + + PSCredential + + PSCredential + + + + + + + + + + System.String, +System.Management.Automation.PSCredential + + + + + + + + + + + + + none + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Mount-LongShare -DriveLetter Z: -NetWorkShare \\contoso\share1 -Verbose + + Maps the network share named share1 to the local drive Z: + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\> + + Mount-LongShare -DriveLetter F: -NetWorkShare \\contoso\share1 -Credential (Get-Credential) + + the credential parameter is used to pass alternate credentials to access the network share "share1" and map it to drive F: + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + $cred = Get-Credential +Mount-LongShare -DriveLetter G: -NetWorkShare \\contoso\share1 -Credential $cred + + the get-credential cmdlet is used to store credentials in the variable 'cred' +the cred variable is then passed to the credential parameter in Mount-LongShare to map Share1 to Drive G: + + + + + + + + Copy-LongItem + + Copies an item from one location to another. + + + + + Copy + LongItem + + + + The Copy-LongItem cmdlet copies an item from one location to another location in the filesystem provider. + + + + + Copy-LongItem + + Path + + Specifies the path to the items to copy. + + String + + + Destination + + Specifies the path to the new location. To rename a copied item, include the new name in the value. + + String + + + Force + + Allows the cmdlet to copy items that cannot otherwise be changed, such as copying over an existing file or directory. + + SwitchParameter + + + NoBuffering + + The copy operation is performed using unbuffered I/O, bypassing system I/O cache resources. Recommended for very large file transfers. + + SwitchParameter + + + + AllowDecryptedDestination + + An attempt to copy an encrypted file will succeed even if the destination copy cannot be encrypted. + + SwitchParameter + + + + + + + + Path + + Specifies the path to the items to copy. + + String + + String + + + None + + + Destination + + Specifies the path to the new location. To rename a copied item, include the new name in the value. + + String + + String + + + None + + + Force + + Allows the cmdlet to copy items that cannot otherwise be changed, such as copying over an existing file or directory. + + SwitchParameter + + SwitchParameter + + + + + + NoBuffering + + The copy operation is performed using unbuffered I/O, bypassing system I/O cache resources. Recommended for very large file transfers. + + SwitchParameter + + SwitchParameter + + + + + + AllowDecryptedDestination + + An attempt to copy an encrypted file will succeed even if the destination copy cannot be encrypted. + + SwitchParameter + + SwitchParameter + + + + + + + + + + System.String + + + + + + + + + + + + + + + None + + + + This cmdlet does not return any output. + + + + + + + + Copy-LongItem + + Copy-LongItem is like the 'cp' or 'copy' commands in other shells. +By default the recurse flag is set so a folder copy operation is always recursive. + + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Copy-LongItem -Path C:\temp\drivers.txt -Destination C:\temp\folder1 -Verbose + + This command copies the drivers.txt file to the C:\temp\folder1 directory. 'folder1' is created if it dosent exist. + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\> + + Copy-LongItem C:\temp\logfiles -Destination C:\temp\newlogs + + This command copies the contents of the C:\Logfiles directory recursively to the C:\temp\newLogs directory. It creates the \newLogs subdirectory if it does not already exist. + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + Copy-LongItem -Path C:\temp\win2012R2.iso -Destination C:\temp\2012R2.iso -Verbose -NoBuffering + + attempts to copy the iso file using unbuffered I/O + + + + + + + + Get-LongChildItem + + Gets the items and child items in one or more specified locations. + + + + + Get + LongChildItem + + + + The Get-LongChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers. + + + + + Get-LongChildItem + + Path + + Specifies a path to one or more locations. Wildcards are NOT permitted. The default location is the current directory. +Path can be relative or absolute. + + String + current directory + + + Filter + + The value of this parameter qualifies the Path parameter. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved. + + String + + + Recurse + + Gets the items in the specified locations and in all child items of the locations. + + SwitchParameter + + + Include + + Gets only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. + + String[] + + + Exclude + + Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. + + String[] + + + Directory + + Gets only the container items in the locations omitting all files.In other words lists only folders and not files. + + SwitchParameter + + + + File + + Gets only the file items in the locations omitting all container\directory items. + + SwitchParameter + None + + + Name + + Gets only the names of the items in the locations. If you pipe the output of this command to another command, only the item names are sent. + + SwitchParameter + + + SkipSymbolicLink + + When this switch is used the enumeration will skip over any symboliclinks in the path. + + SwitchParameter + + + + + + + + Path + + Specifies a path to one or more locations. Wildcards are NOT permitted. The default location is the current directory. +Path can be relative or absolute. + + String + + String + + + current directory + + + Filter + + The value of this parameter qualifies the Path parameter. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved. + + String + + String + + + None + + + Recurse + + Gets the items in the specified locations and in all child items of the locations. + + SwitchParameter + + SwitchParameter + + + false + + + Include + + Gets only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. + + String[] + + String[] + + + None + + + Exclude + + Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted. + + String[] + + String[] + + + None + + + Directory + + Gets only the container items in the locations omitting all files.In other words lists only folders and not files. + + SwitchParameter + + SwitchParameter + + + + + + File + + Gets only the file items in the locations omitting all container\directory items. + + SwitchParameter + + SwitchParameter + + + None + + + Name + + Gets only the names of the items in the locations. If you pipe the output of this command to another command, only the item names are sent. + + SwitchParameter + + SwitchParameter + + + None + + + SkipSymbolicLink + + When this switch is used the enumeration will skip over any symboliclinks in the path. + + SwitchParameter + + SwitchParameter + + + + + + + + + + System.String + + + + You can pipe a string that contains a path to Get-LongChildItem. + + + + + + + + + + Alphaleonis.Win32.Filesystem.FileInfo + + + + For more information see: +http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm + + + + + + + System.String + + + + If you use the Name parameter, Get-ChildItem returns the object names as strings. + + + + + + + + + + You can also refer to Get-LongChildItem by its built-in aliases "ldir", and "lgci". For more information, see about_Aliases. + +Get-LongChildItem gets hidden items by default. + +The Get-LongChildItem cmdlet is designed to work with the data exposed by the AlphaFS Filesystem provider and will NOT work with any other providers E.g.,Registry,Certificates etc + +For more information, see (http://alphafs.alphaleonis.com/doc/2.0/api/html/7C1374.htm). + + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Get-LongChildItem -Path C:\temp -Filter d*.txt -Recurse + + + Directory: C:\temp + +Mode LastWriteTime Length Name +---- ------------- ------ ---- +File 6/27/2015 11:44 AM 1488 drivers.txt +File 7/3/2015 12:30 PM 72 dupes.txt + + + Directory: C:\temp\folder4\DSC06252 + +Mode LastWriteTime Length Name +---- ------------- ------ ---- +File 8/23/2015 6:24 PM 93 dupes.txt + + This command gets all of the files that begin with the letter 'd' followed by any character(s) but end with the extension 'TXT' in the path directory and its subdirectories. The Recurse parameter directs Windows PowerShell to get objects recursively, and it indicates that the subject of the command is the specified directory and its contents. + + + + -------------------------- EXAMPLE 2 -------------------------- + + PS C:\> + + Get-LongChildItem –Path C:\temp -Include *.txt -Exclude A*,c*,e* + + This command lists the .txt files in the temp directory, except for those whose names start with the letter A or C or E. + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + Get-LongChildItem –Path C:\windows\System32\WindowsPowerShell -Filter about*.txt -Recurse -Name + + This command gets only the names of all Text files that begin with 'about' in the C:\windows\System32\WindowsPowerShell directory and its subdirectories. + + + + -------------------------- EXAMPLE 4 -------------------------- + + PS C:\> + + Get-LongChildItem –Path C:\temp -Name -Directory -Recurse + + This command gets only the names of all directories in the C:\temp directory and its subdirectories. + + + + -------------------------- EXAMPLE 5 -------------------------- + + PS C:\> + + Get-LongChildItem -Path C:\temp -Recurse | Where PathLength -gt 260 + + This command gets all files and folders recursively. The output is then piped to Where-object which displays only those files whose length exceeds the windows API 260 character length limitation. + + + + -------------------------- EXAMPLE 6 -------------------------- + + PS C:\> + + Get-LongChildItem -Path D:\Temp + + + Directory: D:\Temp + +Mode LastWriteTime Length Name +---- ------------- ------ ---- +Directory 12/5/2016 9:44 PM 123 +File 12/23/2016 2:46 PM 9491 temp.ps1 SymLink-f 12/7/2016 7:21 PM 0 MySymLinkFile.txt +SymLink-f 12/17/2016 12:38 PM 0 MySymLinkFile2.txt SymLink-d 12/17/2016 12:47 PM symfolder1 +SymLink-d 12/17/2016 12:49 PM symfolder2 +File 12/25/2016 2:10 AM 4405 test.ps1 +File 12/11/2016 1:52 PM 3 testfile1.txt +Directory 12/11/2016 2:26 PM testmodule +File 12/11/2016 2:02 PM 3 thirdfile.txt + + The mode property now shows whether a file or folder is a symlink(symboliclink) and additionaly indicates whether the type is a file or a directory + + + + -------------------------- EXAMPLE 7 -------------------------- + + PS C:\> + + Get-LongChildItem -Path D:\Temp -SkipSymbolicLink + + + Directory: D:\Temp + +Mode LastWriteTime Length Name +---- ------------- ------ ---- +Directory 12/5/2016 9:44 PM 123 +File 12/23/2016 2:46 PM 9491 temp.ps1 File 12/25/2016 2:10 AM 4405 test.ps1 +File 12/11/2016 1:52 PM 3 testfile1.txt +Directory 12/11/2016 2:26 PM testmodule +File 12/11/2016 2:02 PM 3 thirdfile.txt + + lists all items in d:\temp with the exception of symboliclinks + + + + -------------------------- EXAMPLE 8 -------------------------- + + PS C:\temp> + + Get-LongChildItem testdir + + gets items from the folder 'testdir' located in c:\temp + + + + + + + + Get-LongDiskDrive + + List local and mapped drives on the local machine along with their size,freespace and usedspace. + + + + + Get + LongDiskDrive + + + + Includes size percentage as well. + + + + + Get-LongDiskDrive + + + + + + + + + + None + + + + + + + + + + + + + Alphaleonis.Win32.Filesystem.DriveInfo + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Get-LongDiskDrive + +DriveLetter VolumeLabel FileSystem DriveType FreePercent UsedPercent Free Used Size +----------- ----------- ---------- --------- ----------- ----------- ---- ---- ---- +A:\ Unknown Removable 0.00% 0.00% 0 B 0 B 0 B +C:\ NTFS Fixed 19.83% 80.17% 9.84 GB 39.81 GB 49.66 GB +D:\ Source NTFS Fixed 32.67% 67.33% 6.53 GB 13.46 GB 20 GB +E:\ Pagefile NTFS Fixed 98.75% 1.25% 9.87 GB 128.41 MB 10 GB +F:\ Unknown CDRom 0.00% 0.00% 0 B 0 B 0 B + + Lists disk drive stats such as disk space,free used percent etc. + + + + + + + + Get-LongMappedDrive + + List mapped drives + + + + + Get + LongMappedDrive + + + + Lists all mapped network drives on the local machine. + + + + + Get-LongMappedDrive + + + + + + + + + + None + + + + + + + + + + + + + Alphaleonis.Win32.Filesystem.DriveInfo + + + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- + + PS C:\> + + Get-LongMappedDrive | fl * + +UncPath : \\Contoso\Share1\ +DriveLetter : H:\ +FileSystem : NTFS +FreePercent : 11.61% +UsedPercent : 88.39% +Free : 5.79 GB +Used : 44.11 GB +Size : 49.9 GB +AvailableFreeSpace : 6217994240 +DriveFormat : NTFS +DriveType : Network +IsReady : True +Name : H:\ +RootDirectory : H:\ +TotalFreeSpace : 6217994240 +TotalSize : 53580132352 +VolumeLabel : +DiskSpaceInfo : H:\ +DosDeviceName : H: +IsDosDeviceSubstitute : False +IsUnc : True +IsVolume : True +VolumeInfo : + + Lists any mapped drives on the local machine + + + + + + + + DisMount-LongShare + + + + + + + + DisMount + LongShare + + + + Remove a mapped drive + + + + + DisMount-LongShare + + DriveLetter + + The name of a local device to be disconnected, such as "F:". +Note: you may omit the ':' in the drive letter, e.g. F + + String + + + + Force + + Specifies whether the disconnection should occur if there are open files or jobs on the connection. +If this parameter is false or not specified, the function fails if there are open files or jobs +Warning: this may result in loss of unsaved changed so use with care. + + SwitchParameter + + + + + + + + DriveLetter + + The name of a local device to be disconnected, such as "F:". +Note: you may omit the ':' in the drive letter, e.g. F + + String + + String + + + + + + Force + + Specifies whether the disconnection should occur if there are open files or jobs on the connection. +If this parameter is false or not specified, the function fails if there are open files or jobs +Warning: this may result in loss of unsaved changed so use with care. + + SwitchParameter + + SwitchParameter + + + + + + + + + + System.String + + + + + + + + + + + + + none + + + + + + + + + -------------------------- EXAMPLE 1 -------------------------- PS C:\> - Get-LongChildItem -Path C:\temp -Filter d*.txt -Recurse - - - Directory: C:\temp - -Mode LastWriteTime Length Name ----- ------------- ------ ---- -File 6/27/2015 11:44 AM 1488 drivers.txt -File 7/3/2015 12:30 PM 72 dupes.txt - - - Directory: C:\temp\folder4\DSC06252 - -Mode LastWriteTime Length Name ----- ------------- ------ ---- -File 8/23/2015 6:24 PM 93 dupes.txt + DisMount-LongShare -DriveLetter F: - This command gets all of the files that begin with the letter 'd' followed by any character(s) but end with the extension 'TXT' in the path directory and its subdirectories. The Recurse parameter directs Windows PowerShell to get objects recursively, and it indicates that the subject of the command is the specified directory and its contents. + Unmounts any network share that is mounted on F: @@ -414,39 +1514,10 @@ File 8/23/2015 6:24 PM 93 dupes.txt PS C:\> - Get-LongChildItem –Path C:\temp -Include *.txt -Exclude A*,c*,e* - - This command lists the .txt files in the temp directory, except for those whose names start with the letter A or C or E. - - - - -------------------------- EXAMPLE 3 -------------------------- - - PS C:\> - - Get-LongChildItem –Path C:\windows\System32\WindowsPowerShell -Filter about*.txt -Recurse -Name - - This command gets only the names of all Text files that begin with 'about' in the C:\windows\System32\WindowsPowerShell directory and its subdirectories. - - - - -------------------------- EXAMPLE 4 -------------------------- - - PS C:\> - - Get-LongChildItem –Path C:\temp -Name -Directory -Recurse - - This command gets only the names of all directories in the C:\temp directory and its subdirectories. - - - - -------------------------- EXAMPLE 5 -------------------------- - - PS C:\> - - Get-LongChildItem -Path C:\temp -Recurse | Where PathLength -gt 260 + DisMount-LongShare -DriveLetter G -Force - This command gets all files and folders recursively. The output is then piped to Where-object which displays only those files whose length exceeds the windows API 260 character length limitation. + Any open files or connections to the G drive are dropped and then the G drive is unmounted . + @@ -466,8 +1537,7 @@ File 8/23/2015 6:24 PM 93 dupes.txt - The Get-LongItem cmdlet gets the item at the specified location and not the contents of the item at the location. - + The Get-LongItem cmdlet gets the item at the specified location and not the contents of the item at the location. @@ -476,7 +1546,8 @@ File 8/23/2015 6:24 PM 93 dupes.txt Path - Specifies the path to an item. Get-Item gets the item at the specified location. Wildcards are NOT permitted. This parameter is required, but the parameter name ("Path") is optional. + Specifies the path to an item. Get-Item gets the item at the specified location. Wildcards are NOT permitted. This parameter is required, but the parameter name ("Path") is optional. +Path may be relative or absolute String None @@ -488,7 +1559,8 @@ File 8/23/2015 6:24 PM 93 dupes.txt Path - Specifies the path to an item. Get-Item gets the item at the specified location. Wildcards are NOT permitted. This parameter is required, but the parameter name ("Path") is optional. + Specifies the path to an item. Get-Item gets the item at the specified location. Wildcards are NOT permitted. This parameter is required, but the parameter name ("Path") is optional. +Path may be relative or absolute String @@ -501,37 +1573,41 @@ File 8/23/2015 6:24 PM 93 dupes.txt - - You can pipe a string that contains a path to Get-LongItem. - - System.String - + System.String + + You can pipe a string that contains a path to Get-LongItem. + + + - - For more information see: -http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm - Alphaleonis.Win32.Filesystem.FileInfo + + For more information see: +http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm + + + - + + Get-LongItem does not have a Recurse parameter, because it gets only an item, not its contents. To get the contents of an item recursively, use Get-LongChildItem. - + -------------------------- EXAMPLE 1 -------------------------- @@ -547,44 +1623,72 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm - Remove-LongItem + Rename-LongItem - Deletes specified item. + Renames an item in a AlphaFS FileSystem provider namespace. - Remove + Rename LongItem - The Remove-LongItem cmdlet deletes filesystem items. + The Rename-LongItem cmdlet changes the name of a specified item. This cmdlet does not affect the content of the item being renamed. - Remove-LongItem - + Rename-LongItem + Path - Specifies a path to the items being removed. Wildcards are NOT permitted. The parameter name ("-Path") is optional. + Specifies the path to the item to rename. + + String + + + NewName + + Specifies the new name of the item. Enter only a name, not a path and name. + +You cannot use wildcard characters in the value of NewName. To specify a name for multiple files, use the Replace operator in a regular expression. For more information about the Replace operator, type "get-help about_comparison_operators". For a demonstration, see the examples. String - - Recurse + Force - Deletes the items in the specified locations and in all child items of the locations. + Allows the cmdlet to rename items that cannot otherwise be changed, such as read-only files. +Warning: existing files will be replaced when used with this switch SwitchParameter + + + Rename-LongItem + + Path + + Specifies the path to the item to rename. + + String + + + NewExtension + + Reanme only the file extension while retaining the file name. + + String + + Force - Allows the cmdlet to remove items that cannot otherwise be changed, such as read-only files. + Allows the cmdlet to rename items that cannot otherwise be changed, such as read-only files. +Warning: existing files will be replaced when used with this switch SwitchParameter @@ -593,10 +1697,10 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm - + Path - Specifies a path to the items being removed. Wildcards are NOT permitted. The parameter name ("-Path") is optional. + Specifies the path to the item to rename. String @@ -605,14 +1709,16 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm - - Recurse + + NewName - Deletes the items in the specified locations and in all child items of the locations. + Specifies the new name of the item. Enter only a name, not a path and name. + +You cannot use wildcard characters in the value of NewName. To specify a name for multiple files, use the Replace operator in a regular expression. For more information about the Replace operator, type "get-help about_comparison_operators". For a demonstration, see the examples. - SwitchParameter + String - SwitchParameter + String @@ -620,7 +1726,8 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm Force - Allows the cmdlet to remove items that cannot otherwise be changed, such as read-only files. + Allows the cmdlet to rename items that cannot otherwise be changed, such as read-only files. +Warning: existing files will be replaced when used with this switch SwitchParameter @@ -629,35 +1736,48 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm + + NewExtension + + Reanme only the file extension while retaining the file name. + + String + + String + + + + - System.String - + System.String + + + - - This cmdlet does not return any output. - None + + This cmdlet does not return any output. + + + - - - @@ -665,9 +1785,9 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm PS C:\> - Remove-LongItem -Path C:\temp\folder3\drivers.txt -force + Rename-LongItem -path C:\temp\drivers.txt -NewName d1.txt -Verbose -Confirm:$false - This command deletes a file that is read-only. It uses the Path parameter to specify the file. It uses the Force parameter to give permission to delete it. Without Force, you cannot delete read-only files. + This command renames the file drivers.txt to d1.txt @@ -675,9 +1795,31 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm PS C:\> - Remove-LongItem -path C:\temp\folder7\filenames -Recurse + Get-LongChildItem -Path C:\temp\drivers.txt | + Rename-LongItem -NewName {'prefix' + $_.basename + 'Suffix' + $_.extension } + + the file 'drivers.txt' is renamed by piping the output of 'Get-LongChildItem' to Rename-LongItem. The newfilename is created by adding a prefix and a suffix to the filename resulting in the following newname: 'PrefixdriversSuffix.txt'. + + + + -------------------------- EXAMPLE 3 -------------------------- + + PS C:\> + + Get-ChildItem -Path C:\temp -Filter *.txt | Rename-LongItem -NewExtension log -Confirm:$false + +VERBOSE: Performing the operation "Changing Extension" on target "Item: C:\temp\d1.txt Destination: C:\temp\d1.log". +VERBOSE: Rename-LongItem: + C:\temp\d1.txt + C:\temp\d1.log + +VERBOSE: Performing the operation "Changing Extension" on target "Item: C:\temp\d2.txt Destination: C:\temp\d2.log". +VERBOSE: Rename-LongItem: + C:\temp\d2.txt + C:\temp\d2.log - This command deletes the folder 'filenames' including all files and sub-folders. + This command gets all the text files in c:\temp and pipes them to Rename-LongItem which then renames each text file extension from *.txt to *.log +Note: the name os the file is retained(in other words remains unchanged) @@ -685,84 +1827,45 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm - Rename-LongItem + Get-LongFreeDriveLetter - Renames an item in a AlphaFS FileSystem provider namespace. - - - - - Rename - LongItem - - - - The Rename-LongItem cmdlet changes the name of a specified item. This cmdlet does not affect the content of the item being renamed. - - - - - Rename-LongItem - - Path - - Specifies the path to the item to rename. - - String - - - - NewName - - Specifies the new name of the item. Enter only a name, not a path and name. - -You cannot use wildcard characters in the value of NewName. To specify a name for multiple files, use the Replace operator in a regular expression. For more information about the Replace operator, type "get-help about_comparison_operators". For a demonstration, see the examples. - - String - - - - Force - - Allows the cmdlet to rename items that cannot otherwise be changed, such as read-only files. - - SwitchParameter - - - - - - - - Path - - Specifies the path to the item to rename. - - String - - String - - - - - - NewName - - Specifies the new name of the item. Enter only a name, not a path and name. - -You cannot use wildcard characters in the value of NewName. To specify a name for multiple files, use the Replace operator in a regular expression. For more information about the Replace operator, type "get-help about_comparison_operators". For a demonstration, see the examples. - - String - - String - - - - + List free or available drive letters on the local machine + +Get-LongFreeDriveLetter [-Last] [<CommonParameters>] + + + + + Get + LongFreeDriveLetter + + + + By default this cmdlet gets the first available drive letter. + + + + + Get-LongFreeDriveLetter + + + Get-LongFreeDriveLetter + + Last + + When true get the last available drive letter. + + SwitchParameter + + + + + + - Force + Last - Allows the cmdlet to rename items that cannot otherwise be changed, such as read-only files. + When true get the last available drive letter. SwitchParameter @@ -776,7 +1879,7 @@ You cannot use wildcard characters in the value of NewName. To specify a name fo - System.String + None @@ -788,13 +1891,13 @@ You cannot use wildcard characters in the value of NewName. To specify a name fo - - This cmdlet does not return any output. - - None + System.Object + + + @@ -804,9 +1907,12 @@ You cannot use wildcard characters in the value of NewName. To specify a name fo PS C:\> - Rename-LongItem -path C:\temp\drivers.txt -NewName d1.txt -Verbose -Confirm:$false + Get-LongFreeDriveLetter -Verbose +VERBOSE: Get-LongFreeDriveLetter: Listing the first free DriveLetter +G - This command renames the file drivers.txt to d1.txt + + @@ -814,22 +1920,22 @@ You cannot use wildcard characters in the value of NewName. To specify a name fo PS C:\> - Get-LongChildItem -Path C:\temp\drivers.txt | - Rename-LongItem -NewName {'prefix' + $_.basename + 'Suffix' + $_.extension } + Get-LongFreeDriveLetter -Last -Verbose +VERBOSE: Get-LongFreeDriveLetter: Listing the Last free DriveLetter +Z - the file 'drivers.txt' is renamed by piping the output of 'Get-LongChildItem' to Rename-LongItem. The newfilename is created by adding a prefix and a suffix to the filename resulting in the following newname: 'PrefixdriversSuffix.txt'. + + - - New-LongItem - Creates a new item. + Creates new file,folder,symboliclink or hardlink items. @@ -845,77 +1951,95 @@ You cannot use wildcard characters in the value of NewName. To specify a name fo New-LongItem - + Path - Specifies the path to the location of the new item. Wildcards are NOT permitted. - + Specifies the path to the location of the new item. Wildcards are NOT permitted. String[] - - + ItemType Specifies whether you want to create a file or a folder. String - - + + Value + + + + Object + + + Encoding + + + + String + + Force - Allows the cmdlet to create an item that writes over an existing read-only item. + Allows the cmdlet to create an item that writes over an existing read-only item. SwitchParameter - New-LongItem - + Path - Specifies the path to the location of the new item. Wildcards are NOT permitted. - + Specifies the path to the location of the new item. Wildcards are NOT permitted. String[] - - + ItemType Specifies whether you want to create a file or a folder. String - - + + Value + + + + Object + + + Encoding + + + + String + + Name Specifies the name of the new item. You can specify the name of the new item in the Name or Path parameter value, and you can specify the path to the new item in the Name or Path parameter value. String - - + Force - Allows the cmdlet to create an item that writes over an existing read-only item. + Allows the cmdlet to create an item that writes over an existing read-only item. SwitchParameter - - + Path - Specifies the path to the location of the new item. Wildcards are NOT permitted. - + Specifies the path to the location of the new item. Wildcards are NOT permitted. String[] @@ -924,7 +2048,7 @@ You can specify the name of the new item in the Name or Path parameter value, an - + ItemType Specifies whether you want to create a file or a folder. @@ -936,10 +2060,34 @@ You can specify the name of the new item in the Name or Path parameter value, an - + + Value + + + + Object + + Object + + + + + + Encoding + + + + String + + String + + + + + Force - Allows the cmdlet to create an item that writes over an existing read-only item. + Allows the cmdlet to create an item that writes over an existing read-only item. SwitchParameter @@ -948,7 +2096,7 @@ You can specify the name of the new item in the Name or Path parameter value, an - + Name Specifies the name of the new item. @@ -966,26 +2114,30 @@ You can specify the name of the new item in the Name or Path parameter value, an - System.String[] - + System.String[] + + + + + Alphaleonis.Win32.Filesystem.FileInfo + + For more information see: http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm + + - - Alphaleonis.Win32.Filesystem.FileInfo - http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm - @@ -1006,7 +2158,7 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm PS C:\> - New-LongItem -ItemType File -path 'c:\temp\test.txt', 'c:\temp\logs\test.log' + New-LongItem -ItemType File -path 'c:\temp\test.txt', 'c:\temp\logs\test.log' This command uses the New-LongItem cmdlet to create files in two different directories. Because the Path parameter takes multiple strings, you can use it to create multiple items. @@ -1021,161 +2173,69 @@ http://alphafs.alphaleonis.com/doc/2.0/api/html/C308A5E5.htm The New-LongItem cmdlet is used to create the directory tree '123'\'456' which dosent exist and then finally a text file 'hello.txt' inside the '456' directory. - - - - - - - Move-LongItem - - - - - - - Move - LongItem - - - - - - - - - Move-LongItem - - Path - - Specifies the path to the current location of the item.Wildcards are NOT permitted. - - String - - - - Destination - - Specifies the path to the location where the items are being moved. - - String - - - - Force - - Allows the cmdlet to move an item that writes over an existing read-only item - - SwitchParameter - - - - - - - - Path - - Specifies the path to the current location of the item.Wildcards are NOT permitted. - - String - - String - - - - - - Destination - - Specifies the path to the location where the items are being moved. - - String - - String - - - - - - Force - - Allows the cmdlet to move an item that writes over an existing read-only item - - SwitchParameter - - SwitchParameter - - - - - - - - - - System.String - - - - - - - - - - - - - This cmdlet does not return any output. - - - None - - - - - - - -------------------------- EXAMPLE 1 -------------------------- + -------------------------- EXAMPLE 4 -------------------------- PS C:\> - Move-LongItem -path C:\temp\test.txt -destination C:\Temp\folder1\tst.txt + New-LongItem -Path c:\temp\test.txt -ItemType File -Force -Value "1st Line","2nd Line" -Encoding UTF8 - This command moves the Test.txt file from the C:\temp to the C:\Temp\folder1 directory and renames it from "test.txt" to "tst.txt". + Create a text file named test.txt and write 2 lines separated by a line break with UTF8 encoding. - -------------------------- EXAMPLE 2 -------------------------- + -------------------------- EXAMPLE 5 -------------------------- PS C:\> - Move-LongItem -Path C:\temp\logfiles -Destination C:\temp\newlogfiles + New-LongItem -Name test -ItemType Directory - This command moves the C:\Temp\logfiles directory and its contents to the C:\temp\newLogfiles directory. The logfiles directory, and all of its subdirectories and files, then appear in the newLogfiles directory. + a directory named test is created in the current working directory - -------------------------- EXAMPLE 3 -------------------------- + -------------------------- EXAMPLE 6 -------------------------- PS C:\> - Get-LongChildItem -Path C:\temp -Filter *.csv -Recurse | Move-longItem -Destination C:\temp\logs -Verbose + New-LongItem -Name c:\temp\test.txt - This command moves all of the csv files from the c:\temp directory and all subdirectories, recursively, to the C:\temp\logs directory. - -The command uses the Get-LongChildItem cmdlet to get all of the child items in the temp directory and its subdirectories that have a *.csv file name extension. It uses the Recurse parameter to make the retrieval recursive and the filter parameter to limit the retrieval to *.csv files. - -The pipeline operator (|) sends the results of this command to Move-LongItem, which moves the csv files to the logs directory. - -If files being moved to C:\temp\logs have the same name, Move-LongItem displays an warning and continues, but it moves only one file with each name to C:\temp\logs. The other files remain in their original directories. - -If the logs directory (or any other element of the destination path) does not exist, the command fails. The missing directory is not created for you, even if you use the Force parameter. + we use the name parameter instead of path to create a text file named test. + + + + -------------------------- EXAMPLE 7 -------------------------- + + PS C:\> + + New-LongItem -Path C:\temp\MySymlink.txt -Value C:\temp\test.txt -ItemType SymbolicLink + + a symbolic link named mysymlink.txt is created for an existing file named test located at c:\temp + + + + -------------------------- EXAMPLE 8 -------------------------- + + PS C:\> + + New-LongItem -Name MySymlink -Value C:\temp -ItemType SymbolicLink -Force + + a symboliclink named mysymlink is created for c:\temp in the current directory. +Note: since the -Force switch is used any existing symlink named mysymlink will be overwritten. + + + + -------------------------- EXAMPLE 9 -------------------------- + + PS C:\> + + New-LongItem -Path C:\temp\MyHardlink.txt -Value C:\temp\test.txt -ItemType HardLink + + a hardlink named myhardlink is created for the existing file at c:\temp\test.txt - + + \ No newline at end of file diff --git a/lib/AlphaFS.dll b/lib/AlphaFS.dll new file mode 100644 index 0000000..0a7d7c4 Binary files /dev/null and b/lib/AlphaFS.dll differ diff --git a/lib/Net35/AlphaFS.dll b/lib/Net35/AlphaFS.dll new file mode 100644 index 0000000..fc6a4b9 Binary files /dev/null and b/lib/Net35/AlphaFS.dll differ diff --git a/lib/Net40/AlphaFS.dll b/lib/Net40/AlphaFS.dll new file mode 100644 index 0000000..a7af45a Binary files /dev/null and b/lib/Net40/AlphaFS.dll differ diff --git a/lib/Net45/AlphaFS.dll b/lib/Net45/AlphaFS.dll new file mode 100644 index 0000000..fd7857c Binary files /dev/null and b/lib/Net45/AlphaFS.dll differ diff --git a/lib/Net451/AlphaFS.dll b/lib/Net451/AlphaFS.dll new file mode 100644 index 0000000..dcb8057 Binary files /dev/null and b/lib/Net451/AlphaFS.dll differ diff --git a/lib/Net452/AlphaFS.dll b/lib/Net452/AlphaFS.dll new file mode 100644 index 0000000..0a7d7c4 Binary files /dev/null and b/lib/Net452/AlphaFS.dll differ