header image

Archive for September, 2018

Copy-Item Container parameter

Posted by: | September 28, 2018 Comments Off on Copy-Item Container parameter |

The Copy-Item Container parameter controls whether the folder structure is also copied. Lets start with the source material – a folder C:\test with a bunch of files. A destination folder C:\D1 also exists PS> Copy-Item -Path c:\test\* -Destination C:\D1 copies the files from test to D1   PS> Copy-Item -Path c:\test -Destination C:\D1 copies the […]

under: PowerShell

-like oddity

Posted by: | September 28, 2018 Comments Off on -like oddity |

Recently saw a question asking why this code worked PS> $a = ‘aa’ PS> $b = ‘a’ PS> $a -like “*$b*” True PS> Remove-Variable -Name b PS> $a -like “*$b*” True   Set 2 variables and compare using wildcards. The comparison comes back as True as you’d expect. Remove $b and try the comparison again. […]

under: PowerShell

Comparing strings and integers

Posted by: | September 25, 2018 Comments Off on Comparing strings and integers |

Saw an interesting problem involving the comparison of 2 numbers. In reality its was comparing strings and integers. The starting point was a CSV file but as I showed last time you can create a CSV in memory PS> $file = @’ >> “Count”;”Value” >> “3”;”Year1″ >> “1”;”Year1″ >> “5”;”Year3″ >> “8”;”Year4″ >> “10”;”Year15″ >> […]

under: PowerShell

CSV cmdlets

Posted by: | September 24, 2018 Comments Off on CSV cmdlets |

I was reading something and when ConvertFrom-CSV was mentioned it made me pause and think about what that cmdlet actually did. This is a quick explanation of the CSV cmdlets. Export-CSV was available in PowerShell v1. You use it to create a CSV file from PowerShell objects. The code in PowerShell v6.1 is PS> Get-Process […]

under: PowerShell

PowerShell copy file

Posted by: | September 23, 2018 Comments Off on PowerShell copy file |

An article I wrote for searchwindowsserver on PowerShell file copy was published recently. The article is available at https://searchwindowsserver.techtarget.com/tip/PowerShell-commands-to-copy-files-Basic-to-advanced-methods

under: PowerShell

Determining the PowerShell host

Posted by: | September 22, 2018 Comments Off on Determining the PowerShell host |

The PowerShell ecosystem is more diverse than it used to be which makes determining the PowerShell host a bit more difficult. The variable $host, and its Name property, is a good starting point. PS> $host.Name ConsoleHost   You get ConSoleHost if you’re running in the console. For ISE you get – Windows PowerShell ISE Host […]

under: PowerShell

Splitting paths

Posted by: | September 21, 2018 Comments Off on Splitting paths |

PowerShell has the Split-Path cmdlet that provides the leaf and parent of a path. But what if you’re splitting paths and need one or paths at a higher level. Consider the path PS> $path = ‘C:\Scripts\HyperV\Admin\Optimize-VMDisks.ps1’   Its just an arbitrary path from my test machine. Using Split-Path you can get the parent (by default) […]

under: File System, PowerShell

PowerShell v6.1

Posted by: | September 19, 2018 Comments Off on PowerShell v6.1 |

PowerShell v6.1 was released last week – there’s no big ticket items like v6.0 but a lot of bug fixes and minor improvements. You can download from https://github.com/PowerShell/PowerShell/releases   and find the release notes at https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-core-61?view=powershell-6

under: PowerShell v6

Get-Date –DisplayHint

Posted by: | September 13, 2018 Comments Off on Get-Date –DisplayHint |

On the surface Get-Date is a simple cmdlet that’s been around since PowerShell v1. However, it has some interesting quirks. In this post I’ll show how Get-Date –DisplayHint works. By default Get-Date returns the data and time PS> Get-Date 13 September 2018 16:09:34 The DisplayHint parameter ( available in PowerShell v5.1, 6.0 and 6.1) modifies […]

under: PowerShell

PowerShell new line

Posted by: | September 9, 2018 Comments Off on PowerShell new line |

A PowerShell new line can be generated using `n. It’s one of a series of special characters recognised by PowerShell. The full list of Windows PowerShell v5.1 special characters is: `0 Null `a Alert `b Backspace `f Form feed `n New line `r Carriage return `t Horizontal tab `v Vertical tab –% Stop parsing   […]

under: PowerShell, PowerShell v5, PowerShell v6

Older Posts »

Categories