Why are all newlines gone after PowerShell’s Get-Content, Regex, and Set-Content?

For the $replacement variable, you don’t really need to specify the type [string], PowerShell will infer that from the assignment. For the $template variable, [string] is actually wrong. By default, Get-Content will give you an array of strings (i.e. lines) instead of one string. But in fact you don’t even want to split the input … Read more

Remove alias in script

The following seems to work If (Test-Path Alias:wget) {Remove-Item Alias:wget} If (Test-Path Alias:wget) {Remove-Item Alias:wget} wget The first line removes the Script level alias, and the second removes the Global level alias. Note that both need to be tested, because if the Global doesn’t exist the Script isn’t created. Also this misbehaves in that it … Read more

Powershell – Set SSL Certificate on https Binding

You have to assign the certifcate to a specific site. You can retrieve the binding information of your site using the Get-WebBinding cmdlet and set the SSL Certificate using the AddSslCertificate function: $siteName=”mywebsite” $dnsName=”www.mywebsite.ru” # create the ssl certificate $newCert = New-SelfSignedCertificate -DnsName $dnsName -CertStoreLocation cert:\LocalMachine\My # get the web binding of the site $binding … Read more

Exception calling “DownloadFile” with “2” argument(s): “An exception occurred during a WebClient request.

If you look at the MSDN documentation for the DownloadFile method, you’ll notice that the second parameter is a filename, not a directory. So, if you re-define $destination to something like: $destination = “c:\CHPACS\java-installer.zip” then it should work. Check secondly that the file that you’re trying to download isn’t open or being executed at the … Read more

Converting LastLogon to DateTime format

DateTime.FromFileTime should do the trick: PS C:\> [datetime]::FromFileTime(129948127853609000) Monday, October 15, 2012 3:13:05 PM Then depending on how you want to format it, check out standard and custom datetime format strings. PS C:\> [datetime]::FromFileTime(129948127853609000).ToString(‘d MMMM’) 15 October PS C:\> [datetime]::FromFileTime(129948127853609000).ToString(‘g’) 10/15/2012 3:13 PM If you want to integrate this into your one-liner, change your select … Read more

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