PS: File/Folder Copying in PowerShell

Many times we require to copy a few bytes of single file to a few GBs of DB files on the other.  Here are basic PS cmdlets that help you script/automate the tasks safely in PS. Important Notes on Copy Behavior: Copy process merges the source files with destination path You need to use forceful copy if the destination folder already exists If destination folder doesn’t exist, creates destination folder with files under sources folder instead of copying the whole folder as is If destination folder exists, copy process copies the whole source folder as subfolder in the destination folder […]

Read more

PS: Check File/Folder/Drive/Path/Location Existence

In scripting very often we come across need to dynamically create a path (file/folder), for which you would like to perform a existence check before you attempt to create a folder. DRIVE existence/availability check: $drive = ‘Z:’ if (Test-Path -path $drive) {     write-host "$drive drive exists" } else {     write-host "$drive drive does NOT exists" } PS C:> if (Test-Path -path Z:) { write-host "Z: drive exists" } else { write-host "Z: drive does NOT exists" } Z: drive does NOT exists PS C:> FILE existence/availability check: $file= ‘C:TEMPTestFile.txt’ if (Test-Path -path $file) {     write-host "$file exists" […]

Read more

Windows Explorer Folder Descriptions

Windows saves all of it’s system wide Windows Explorer folder settings in below location: C:>reg query "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerFolderDescriptions" /s | grep -i –P "path|name"     Name    REG_SZ    Common Programs     RelativePath    REG_SZ    Programs     LocalizedName    REG_EXPAND_SZ    @%SystemRoot%system32shell32.dll,-21782     Name    REG_SZ    GameTasks     RelativePath    REG_SZ    MicrosoftWindowsGameExplorer     Name    REG_SZ    UserProfiles     LocalizedName    REG_EXPAND_SZ    @%SystemRoot%system32shell32.dll,-21813     Name    REG_SZ    MyComputerFolder     ParsingName    REG_SZ    ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}     Name    REG_SZ    SyncSetupFolder     ParsingName    REG_SZ    ::{26EE0668-A00A-44D7-9371-BEB064C98683}::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}::{F139 0A9A-A3F4-4E5D-9C5F-98F3BD8D935C},     Name    REG_SZ    DpapiKeys     Name    REG_SZ    SamplePlaylists     RelativePath    REG_SZ    Sample Playlists     LocalizedName    REG_EXPAND_SZ    @%SystemRoot%system32shell32.dll,-21820     Name    REG_SZ    Favorites     RelativePath    REG_SZ    Favorites     LocalizedName    REG_EXPAND_SZ    @%SystemRoot%system32shell32.dll,-21796     PublishExpandedPath    […]

Read more