All private Components are recorded here. (Only for Contributors)
-
Description
Assert if the current process is in AdminPermission.
-
Inputs
None.
-
Outputs
None.
-
Description
Assert the robocopy command is available. Assert if the current platform is Windows. Assert if the current process is in AdminPermission
-
Inputs
None.
-
Outputs
None.
-
Description
Assert the robocopy command is available. Assert if the current platform is Windows. Assert if the current process is in AdminPermission
-
Inputs
None.
-
Outputs
None.
-
Description
Assert if the current platform is Linux or Wsl2.
-
Inputs
None.
-
Outputs
None.
-
Description
Assert if the current platform is Windows.
-
Inputs
None.
-
Outputs
None.
-
Description
Assert if the current platform is Windows and the current process is in AdminPermission.
-
Inputs
None.
-
Outputs
None.
-
Description
Assert if the current platform is Windows and the current process is in AdminPermission.
-
Inputs
None.
-
Outputs
None.
-
Synopsis
Check if a path is valid as the rule defined in the post.
-
Description
Check if $Path is valid as the rule defined in the post. Only the following 4 types of paths are valid:
- root path of Non-system disk
- other path in Non-system disk
- path of ${Home}
- other path in ${Home}
-
Parameter
$PathThe path to be checked.
-
Inputs
String or FormattedFileSystemPath.
-
Outputs
None.
-
Link
-
Description
Copy a simple directory to a destination. If the destination exists, the source directory will be merged to the destination directory. Before the merging, both the source and destination will be backup to a directory.
-
Parameter
$PathThe source directory path.
-
Parameter
$DestinationThe destination directory path.
-
Parameter
$BackupDirThe backup directory path.
-
Parameter
$IndicatorThe indicator string to indicate the backup directory.
-
Inputs
String or FormattedFileSystemPath. String. String or FormattedFileSystemPath. String.
-
Outputs
None.
-
Notes
Only support a simple directory. Do not support a file, a directory symbolic link, or a junction point. Try Robocopy first, if failed, use Copy-Item instead. But Copy-Item will loss the metadata of directories in the source. Patched to avoid Copy-Item's ambiguity: If the destination is existing, Copy-Item will merge the source to the destination. (Items within the source will be copied and to the destination, covering the existing items with the same name.) If the destination is non-existing, Copy-Item will create a new directory with the source's name.
Refer to the doc for more information about Copy-Item.
Robocopy args effections /e Copies subdirectories. This option automatically includes empty directories. /copyall Copies all file information (equivalent to /copy:DATSOU). /dcopy:DATE Specifies what to copy in directories. D-Data A-Attributes T-Time stamps E-Extended attribute /log+: Writes the status output to the log file (appends the output to the existing log file). -
Link
-
Description
Copy a simple file to a destination. If the destination exists, the source file will cover the destination file. Before the covering, the destination file will be backup to a directory.
-
Parameter
$PathThe source file path.
-
Parameter
$DestinationThe destination file path.
-
Parameter
$BackupDirThe backup directory path.
-
Parameter
$IndicatorThe indicator string to indicate the backup file.
-
Inputs
String or FormattedFileSystemPath. String. String or FormattedFileSystemPath. String.
-
Outputs
None.
-
Notes
Only support a simple file. Do not support a directory, a file symbolic link, or a hard link.
-
Link
-
Description
Convert a function doc to markdown string with a fixed format.
-
Notes
The formatted markdown string is like this:
- Synopsis xxx - Description xxx - Parameters `$Aa` xxx - Parameters `$Bb` xxx
-
Inputs
String.
-
Outputs
String.
-
Description
Get class docs from a script file. Return a hashtable with class names as keys and class docs as values.
-
Inputs
String.
-
Outputs
Hashtable.
-
Description
Get the current log file name in a fixed and internal rotating list. The current (target) log file is the one that is the most recently modified and whose size is less than 10MB.
-
Inputs
None.
-
Outputs
String.
-
Synopsis
Get the default SDDL of a specific path type that defined in
Get-PathType. -
Description
Get the default SDDL of the
$PathType. The relationship between the$PathTypeand its default SDDL are the following mappings:Type SDDL NonSystemDisk[NTFS]\RootO:SYG:SYD:AI(A;OICIIO;SDGXGWGR;;;AU)(A;;0x1301bf;;;AU)(A;;FA;;;SY)(A;OICIIO;GA;;;SY)(A;OICIIO;GA;;;BA)(A;;FA;;;BA)(A;;0x1200a9;;;BU)(A;OICIIO;GXGR;;;BU)NonSystemDisk[ReFS]\RootO:BAG:SYD:AI(A;OICIIO;SDGXGWGR;;;AU)(A;;0x1301bf;;;AU)(A;OICIIO;GA;;;SY)(A;;FA;;;SY)(A;OICI;FA;;;BA)(A;;0x1200a9;;;BU)(A;OICIIO;GXGR;;;BU)Home\RootO:BAG:SYD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;FA;;;${UserSid})NonSystemDisk[NTFS]\System Volume InformationO:BAG:SYD:PAI(A;OICI;FA;;;SY)NonSystemDisk[NTFS]\$Recycle.BinO:${UserSid}G:${UserSid}D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;;0x1201ad;;;BU)NonSystemDisk[ReFS]\System Volume InformationO:BAG:SYD:PAI(A;OICI;FA;;;SY)NonSystemDisk[ReFS]\$Recycle.BinO:${UserSid}G:${UserSid}D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;;0x1201ad;;;BU)Home\DirectoryO:${UserSid}G:${UserSid}D:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;${UserSid})Home\SymbolicLinkDirectoryO:BAG:${UserSid}D:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;${UserSid})Home\JunctionO:${UserSid}G:${UserSid}D:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;${UserSid})NonSystemDisk[NTFS]\DirectoryO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)NonSystemDisk[NTFS]\SymbolicLinkDirectoryO:BAG:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)NonSystemDisk[NTFS]\JunctionO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)NonSystemDisk[ReFS]\DirectoryO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)NonSystemDisk[ReFS]\SymbolicLinkDirectoryO:BAG:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)NonSystemDisk[ReFS]\JunctionO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)Home\desktop.iniO:${UserSid}G:${UserSid}D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;${UserSid})Home\SymbolicLinkFileO:BAG:${UserSid}D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;${UserSid})Home\FileO:${UserSid}G:${UserSid}D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;${UserSid})Home\HardLinkO:${UserSid}G:${UserSid}D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;${UserSid})NonSystemDisk[NTFS]\desktop.iniO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)NonSystemDisk[NTFS]\SymbolicLinkFileO:BAG:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)NonSystemDisk[NTFS]\FileO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)NonSystemDisk[NTFS]\HardLinkO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)NonSystemDisk[ReFS]\desktop.iniO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)NonSystemDisk[ReFS]\SymbolicLinkFileO:BAG:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)NonSystemDisk[ReFS]\FileO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)NonSystemDisk[ReFS]\HardLinkO:${UserSid}G:${UserSid}D:AI(A;ID;0x1301bf;;;AU)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;0x1200a9;;;BU)where,
$UserSid = (Get-LocalUser -Name ([Environment]::UserName)).SID.Value. AllSDDLsare from a origin installed native system, so we can ensure it is in the default state. -
Parameter
$PathTypeThe path type to be checked.
-
Inputs
String.
-
Outputs
String or Null.
-
Link
-
Description
Get function docs from a script file. Return a hashtable with function names as keys and function docs as values.
-
Inputs
String.
-
Outputs
Hashtable.
-
Description
Get the log file name according the key info, pre-defined
$LoggingPathand pre-defined$ModuleVersion. -
Parameter
$KeyInfoA string to indicate the key info of the log file name.
-
Inputs
String.
-
Outputs
String.
-
Synopsis
Get a customized path type of a fileSystem path(disk, directory, file, link, etc.), according to the
Types of Itemsdescribed in the post. -
Description
Basing on
New-Item -ItemType, this function defines 38 types of items, including the 28 types of items that defined in the post.Types Description Path Example NonSystemDisk[NTFS]\RootX:\NonSystemDisk[ReFS]\RootX:\NonSystemDisk[FAT32]\RootX:\Home\Root${Home}\NonSystemDisk[NTFS]\System Volume InformationX:\System Volume Information\NonSystemDisk[ReFS]\System Volume InformationX:\System Volume Information\NonSystemDisk[FAT32]\System Volume InformationX:\System Volume Information\NonSystemDisk[NTFS]\$Recycle.BinX:\$Recycle.Bin\NonSystemDisk[ReFS]\$Recycle.BinX:\$Recycle.Bin\NonSystemDisk[FAT32]\$Recycle.BinX:\$Recycle.Bin\Home\Directory${Home}\*some_nomrmal_dir\Home\SymbolicLinkDirectory${Home}\*some_symbolic_link_dir\Home\Junction${Home}\*some_junction\NonSystemDisk[NTFS]\DirectoryX:\*some_nomrmal_dir\NonSystemDisk[ReFS]\DirectoryX:\*some_nomrmal_dir\NonSystemDisk[FAT32]\DirectoryX:\*some_nomrmal_dir\NonSystemDisk[NTFS]\SymbolicLinkDirectoryX:\*some_symbolic_link_dir\NonSystemDisk[ReFS]\SymbolicLinkDirectoryX:\*some_symbolic_link_dir\NonSystemDisk[FAT32]\SymbolicLinkDirectoryX:\*some_symbolic_link_dir\NonSystemDisk[NTFS]\JunctionX:\*some_junction\NonSystemDisk[ReFS]\JunctionX:\*some_junction\NonSystemDisk[FAT32]\JunctionX:\*some_junction\Home\desktop.ini${Home}\*desktop.iniHome\SymbolicLinkFile${Home}\*some_symbolic_link_fileHome\File${Home}\*some_normal_fileHome\HardLink${Home}\*some_hardlinkNonSystemDisk[NTFS]\desktop.iniX:\*desktop.iniNonSystemDisk[ReFS]\desktop.iniX:\*desktop.iniNonSystemDisk[FAT32]\desktop.iniX:\*desktop.iniNonSystemDisk[NTFS]\SymbolicLinkFileX:\*some_symbolic_link_fileNonSystemDisk[ReFS]\SymbolicLinkFileX:\*some_symbolic_link_fileNonSystemDisk[FAT32]\SymbolicLinkFileX:\*some_symbolic_link_fileNonSystemDisk[NTFS]\FileX:\*some_normal_fileNonSystemDisk[ReFS]\FileX:\*some_normal_fileNonSystemDisk[FAT32]\FileX:\*some_normal_fileNonSystemDisk[NTFS]\HardLinkX:\*some_hardlinkNonSystemDisk[ReFS]\HardLinkX:\*some_hardlinkNonSystemDisk[FAT32]\HardLinkX:\*some_hardlinkHere
NonSystemDisk[NTFS/ReFS/FAT32]means,Xis not system disk drive letter andX:\is in one of NTFS/ReFS/FAT32 file system. When output, a spcific file system will be shown, such asNonSystemDisk[NTFS]. HereHomemeans be or in${Home}directory.Actually, some paths have a hierarchical relationship and can belong to both types as the above, and we return only the first type recognized in the above order. That is to say, the above shown order is the key to identify all customized path types.
-
Parameter
$PathThe path to be checked to get its type.
-
Parameter
$SkipPlatformCheckSwitch to disable platform check at the beginning. If true(given), the platform will not be checked at the beginning.
-
Parameter
$SkipPathCheckSwitch to disable path check at the beginning. If true(given), the path will not be checked at the beginning.
-
Inputs
String or FormattedFileSystemPath.
-
Outputs
String or Null.
-
Link
-
Description
Get sorted function names with docs from a script file or script files. Return a hashtable enumerator with sorted function names as keys(names) and function docs as values.
-
Parameter
$PathThe path of a script file or script files.
-
Parameter
$DocTypeThe type of docs, 'Function' or 'Class'.
-
Inputs
String[]. String.
-
Outputs
System.Collections.DictionaryEntry.
-
Link
-
Synopsis
Fro some purposes about setting a soft link (symbolic link or junction point), move the target item to the source, if the target and the source meet some conditions. Backup can be conducted when needed. Then the target item will be removed, along with some post-processing procedures.
-
Description
When we want to set a soft link (symbolic link or junction point) from
AtoB, as$A\rightarrow B$ , we may find thatAis non-existing whileBis existing. That is not our expectation. We may need to moveBtoAat first, then go back to set the link$A\rightarrow B$ .Worsely, if we find
AandBare both existing at first, we may need to consider merging or backuping procedures.This function can help users to do the above things easily, i.e., it can move the target item to the source automatically, with essential backup. It can be used before setting a soft link from the source to the target.
-
Parameter
$TargetThe target item path.
-
Parameter
$SourceThe source item path.
-
Parameter
$BackupDirThe backup directory path.
-
Inputs
String. String. String or FormattedFileSystemPath.
-
Outputs
None.
-
Notes
This function is not generic and is more of an integration for a class of business. The following are the main rules of this function:
First, check the target and source path if they are both in the following conditions:
- non-existing
- existing-simple-file
- existing-simple-directory
- existing-file-symbolic-link
- existing-directory-symbolic-link
- existing-directory-junction-point
Second, there are 6*6=36 combinations of the target and source path. For each combination, we have a specific operation:
Conditions Target Source Opeartion 1 non-existing non-existing throw error 1 non-existing existing-simple-file pass(do nothing) 1 non-existing existing-simple-directory pass(do nothing) 3 non-existing one of the 3 link types throw error 1 existing-simple-file non-existing copy target to source, del target 1 existing-simple-file existing-simple-file backup source, copy target to cover source, del target 1 existing-simple-file existing-simple-directory throw error 3 existing-simple-file one of the 3 link types throw error 1 existing-simple-directory non-existing copy target to source, del target 1 existing-simple-directory existing-simple-file throw error 1 existing-simple-directory existing-simple-directory backup source, backup target, merge target to source (items within target will cover), del target 3 existing-simple-directory one of the 3 link types throw error 1 existing-file-symbolic-link non-existing throw error 1 existing-file-symbolic-link existing-simple-file del target 1 existing-file-symbolic-link existing-simple-directory throw error 3 existing-file-symbolic-link one of the 3 link types throw error 1 existing-directory-symbolic-link non-existing throw error 1 existing-directory-symbolic-link existing-simple-file throw error 1 existing-directory-symbolic-link existing-simple-directory del target 3 existing-directory-symbolic-link one of the 3 link types throw error 1 existing-directory-junction-point non-existing throw error 1 existing-directory-junction-point existing-simple-file throw error 1 existing-directory-junction-point existing-simple-directory del target 3 existing-directory-junction-point one of the 3 link types throw error The other conditions out of the above 36 conditions will throw error as well.
-
Link
-
Synopsis
Reset the attributes of a path to the original status, when the path matches one of the special path types that are defined in this function.
-
Description
Reset the attributes of $Path to the original status, when it matches one of the following 8 types (appended with corresponding standard attriibuts):
Type Specific Path Example Default Attributes Directory X:\Hidden, System, Directory Directory X:\System Volume Information\Hidden, System, Directory Directory X:\$Recycle.Bin\Hidden, System, Directory Directory X:\*some_symbolic_link_dir\Directory, ReparsePoint Directory X:\*some_junction\Directory, ReparsePoint File X:\*desktop.iniHidden, System, Archive File X:\*some_symbolic_link_fileArchive, ReparsePoint File X:\*some_hardlinkArchive Here the
Xrepresents any drive disk letter. And, ifXrepresents the system disk drive letter, the path should only be or in${Home}. Other directories' attributes will not be reset. And other files' attributes will not be reset. See the post for more details.Many (perhaps all) attributes can be find by
[enum]::GetValues([System.IO.FileAttributes]):ReadOnly, Hidden, System, Directory, Archive, Device, Normal, Temporary, SparseFile, ReparsePoint, Compressed, Offline, NotContentIndexed, Encrypted, IntegrityStream, NoScrubData.
We can use the command
Set-ItemProperty $Path -Name Attributes -Value $some_attributes. But$some_attributescan only supportArchive, Hidden, Normal, ReadOnly, or Systemand their permutations.So, to reset the attributes to standard status, we cannot directly give the target attributes, but use a specific
$some_attributes. -
Parameter
$PathThe path to be checked to reset its attributes.
-
Parameter
$SkipPlatformCheckSwitch to disable platform check at the beginning. If true(given), the platform will not be checked at the beginning.
-
Parameter
$SkipPathCheckSwitch to disable path check at the beginning. If true(given), the path will not be checked at the beginning.
-
Inputs
String or FormattedFileSystemPath.
-
Outputs
None.
-
Component
To set the attributes of
$Path:Set-ItemProperty $Path -Name Attributes -Value $some_attributes
-
Link
-
Description
Test if the current process is in AdminPermission.
-
Inputs
None.
-
Outputs
Boolean.
-
Description
Test if the current platform is Wsl2.
-
Inputs
None.
-
Outputs
Boolean.
-
Description
Test if the current platform is compatible with the arg
$Name. Currently, it only support Windows, MacOS, Linux and Wsl2. If$Verboseis given, it will show the result. -
Parameter
$NameThe platform name to be tested.
-
Parameter
$VerboseWhether to show the result.
-
Example
Test-Platform -Name 'Windows' -Verbose Test-Platform -Name 'Wsl2' -Verbose Test-Platform -Name 'Linux' -Verbose Test-Platform -Name 'MacOS' -Verbose
-
Inputs
String.
-
Outputs
Boolean.
-
Link
Automatic Variables for
$IsWindowsand$IsLinux.
-
Description
Write log to a file.
-
Parameter
$MessageThe message to be logged.
-
Inputs
String.
-
Outputs
None.
-
Notes
If the log file does not exist, it will be created automatically. But the creation results will be muted to avoid some errors about bool function's return value.
-
Description
Can write log to a file and output to the console simultaneously. Logging to a file is the default behavior. Logging to the console is an optional behavior, which can be controlled by the switch parameter
$ShowVerbose. -
Parameter
$MessageThe message to be logged.
-
Parameter
$ShowVerboseWhether to show the message to the console in verbose mode.
-
Inputs
String.
-
Outputs
None.