How do I use Format-Table without truncation of values?

The $FormatEnumerationLimit preference variable doesn’t apply here, because its purpose is to determine how many elements of a collection-valued property to display (e.g, $FormatEnumerationLimit = 2; [pscustomobject] @{ prop = 1, 2, 3 } prints (at most) 2 elements from .prop‘s value and hints at the existence of more with …; e.g., {1, 2…}). Instead, … Read more

Is there a way to make certain functions “private” in a PowerShell script?

In fact, if you call a .ps1 file, by default any functions and variables declared within it are scoped privately within the script (this is referred to as “script scope”). Since you’re seeing both functions defined globally, I infer that you’re dot-sourcing SvcTest.ps1, i.e. invoking it like this PS> . <path>\SvcTest.ps1 rather than calling it … Read more

How to retrieve a recursive directory and file list from PowerShell excluding some files and folders?

I like Keith Hill’s answer except it has a bug that prevents it from recursing past two levels. These commands manifest the bug: New-Item level1/level2/level3/level4/foobar.txt -Force -ItemType file cd level1 GetFiles . xyz | % { $_.fullname } With Hill’s original code you get this: …\level1\level2 …\level1\level2\level3 Here is a corrected, and slightly refactored, version: … Read more

powershell v2 remoting – How do you enable unencrypted traffic

AllowEncrypted is defined on the client end, via the WSMAN: drive. You must be running powershell.exe (or powershell_ise.exe) as an elevated process. ps> cd WSMan:\localhost\Client ps> dir Name Value —- —– NetworkDelayms 5000 URLPrefix wsman AllowUnencrypted false Auth DefaultPorts TrustedHosts You would change it like so (after changing to the directory above): Set-Item .\allowunencrypted $true … Read more

How to strip illegal characters before trying to save filenames?

Casting the character array to System.String actually seems to join the array elements with spaces, meaning that [string][System.IO.Path]::GetInvalidFileNameChars() does the same as [System.IO.Path]::GetInvalidFileNameChars() -join ‘ ‘ when you actually want [System.IO.Path]::GetInvalidFileNameChars() -join ” As @mjolinor mentioned (+1), this is caused by the output field separator ($OFS). Evidence: PS C:\> [RegEx]::Escape([string][IO.Path]::GetInvalidFileNameChars()) “\ \ \|\ \ ☺\ … Read more

How to capture the exception raised in the scriptblock of start-job?

Using throw will change the job object’s State property to “Failed”. The key is to use the job object returned from Start-Job or Get-Job and check the State property. You can then access the exception message from the job object itself. Per your request I updated the example to also include concurrency. $createZip = { … Read more

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