Custom RoboCopy Progress Bar in PowerShell

I wrote a PowerShell function called Copy-WithProgress that will achieve what you are after. Since you specifically stated that you were using robocopy, I built a PowerShell function that encapsulates the robocopy functionality (at least, parts of it). Allow me to show you how it works. I’ve also recorded and posted a YouTube video demonstrating … Read more

Powershell equivalent of bash ampersand (&) for forking/running background processes

As long as the command is an executable or a file that has an associated executable, use Start-Process (available from v2): Start-Process -NoNewWindow ping google.com You can also add this as a function in your profile: function bg() {Start-Process -NoNewWindow @args} and then the invocation becomes: bg ping google.com In my opinion, Start-Job is an … Read more

PowerShell script runs when pasted into the PowerShell window, but not when run from shortcut

To clarify: It is perfectly fine to use Unicode (non-ASCII-range) quotation marks such as “ in PowerShell – see the bottom section. However, in order to use such characters in script files, these files must use a Unicode character encoding such as UTF-8 or UTF-16LE (“Unicode”). Your problem was that your script file was saved … Read more

Combine `Get-Disk` info and `LogicalDisk` info in PowerShell?

You need to query several WMI classes to get all information you want. Win32_DiskDrive gives you information about the physical disks. Win32_DiskPartition gives you information about the partitions on the physical disks. Win32_LogicalDisk gives you information about the filesystems inside the partitions. Partitions can be mapped to their disks using the Win32_DiskDriveToDiskPartition class, and drives … Read more

PowerShell script to check an application that’s locking a file?

You can do this with the SysInternals tool handle.exe. Try something like this: PS> $handleOut = handle PS> foreach ($line in $handleOut) { if ($line -match ‘\S+\spid:’) { $exe = $line } elseif ($line -match ‘C:\\Windows\\Fonts\\segoeui\.ttf’) { “$exe – $line” } } MSASCui.exe pid: 5608 ACME\hillr – 568: File (—) C:\Windows\Fonts\segoeui.ttf …

Convert a secure string to plain text

You are close, but the parameter you pass to SecureStringToBSTR must be a SecureString. You appear to be passing the result of ConvertFrom-SecureString, which is an encrypted standard string. So call ConvertTo-SecureString on this before passing to SecureStringToBSTR. $SecurePassword = ConvertTo-SecureString $PlainPassword -AsPlainText -Force $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)