Copy-Item is overwriting by default

When in doubt, read the documentation. -Force Allows the cmdlet to copy items that cannot otherwise be changed, such as copying over a read-only file or alias. The default behavior for Copy-Item is to replace existing items. The -Force switch is only to enforce replacement if for instance the destination file has the readonly attribute set. You can use -Confirm to get … Read more

You cannot call a method on a null-valued expression

The simple answer for this one is that you have an undeclared (null) variable. In this case it is $md5. From the comment you put this needed to be declared elsewhere in your code The error was because you are trying to execute a method that does not exist. The .ComputeHash() of $md5.ComputeHash() was the null valued expression. Typing in … Read more

How to unzip a file in Powershell?

Here is a simple way using ExtractToDirectory from System.IO.Compression.ZipFile: Note that if the target folder doesn’t exist, ExtractToDirectory will create it. Other caveats: Existing files will not be overwritten and instead trigger an IOException. This method requires at least .NET Framework 4.5, available for Windows Vista and newer. Relative paths are not resolved based on the current working … Read more

Path to Powershell.exe (v 2.0)

I believe it’s in C:\Windows\System32\WindowsPowershell\v1.0\. In order to confuse the innocent, MS kept it in a directory labeled “v1.0”. Running this on Windows 7 and checking the version number via $Host.Version (Determine installed PowerShell version) shows it’s 2.0. Another option is type $PSVersionTable at the command prompt. If you are running v2.0, the output will be: If you’re running version … Read more

Read file line by line in PowerShell

Not much documentation on PowerShell loops. Documentation on loops in PowerShell is plentiful, and you might want to check out the following help topics: about_For, about_ForEach, about_Do, about_While. Another idiomatic PowerShell solution to your problem is to pipe the lines of the text file to the ForEach-Object cmdlet: Instead of regex matching inside the loop, you could pipe the lines through Where-Object to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)