Here’s some links for other PowerShell articles I’ve written recently https://searchwindowsserver.techtarget.com/tip/PowerShell-commands-to-copy-files-Basic-to-advanced-methods https://searchwindowsserver.techtarget.com/tutorial/PowerShell-commands-for-Active-Directory-Groups-management https://searchwindowsserver.techtarget.com/tip/PowerShell-Core-61-offers-many-small-improvements https://searchwindowsserver.techtarget.com/tutorial/How-PowerShell-Direct-helps-polish-off-those-VMs https://searchwindowsserver.techtarget.com/tutorial/Working-with-PowerShell-module-downloads-from-the-gallery Enjoy
Archive for December, 2018
PowerShell articles
Posted by: richardsiddaway | December 31, 2018 Comments Off on PowerShell articles |Change file times
Posted by: richardsiddaway | December 30, 2018 Comments Off on Change file times |When a file is created, accessed or modified that time is recorded. This is how to change file times. There are three properties to consider: CreationTime LastAccessTime LastWriteTime Just to add to the fun there are UTC (GMT in real world) times as well: CreationTimeUtc LastAccessTimeUtc LastWriteTimeUtc If you need to change a […]
Get first non-repeating character in a string
Posted by: richardsiddaway | December 29, 2018 Comments Off on Get first non-repeating character in a string |How do you get first non-repeating character in a string. In Windows PowerShell v5.1 you could use Group-Object but as I showed last time that approach has been taken away in PowerShell v6.1. Instead you need to loop through the characters in the string and count them function get-firstnonrepeatcharacter { [CmdletBinding()] param ( […]
Group-Object change in PowerShell v6.1
Posted by: richardsiddaway | December 29, 2018 Comments Off on Group-Object change in PowerShell v6.1 |There’s a subtle Group-Object change in PowerShell v6.1. In PowerShell v5.1 if you do this: $ts = ‘ffrluoluntlvxutxbdvbktgyyvsvcrkxoyfotzkzogcwuwycmnhuedk’ $ts.ToCharArray() | group You get this: Count Name Group —– —- —– 3 f {f, f, f} 2 r {r, r} 3 l {l, l, l} 5 u {u, u, u, u…} 4 o {o, o, […]
If you’re given a string how would you go about counting vowels, consonants and non-alphabet characters. My approach would be: function measure-vowel { [CmdletBinding()] param ( [string]$teststring ) $counts = [ordered]@{ Vowels = 0 Consonants = 0 NonAlphabet = 0 } $vowels = 97, 101, 105, 111, 117 $teststring.ToLower().ToCharArray() | foreach { $test […]
Create a random string
Posted by: richardsiddaway | December 27, 2018 Comments Off on Create a random string |I often need to create a random string of characters. Here’s a simple function to achieve that: function get-randomstring { [CmdletBinding()] param ( [int]$length ) $rca = 1..$length | foreach { $ran = Get-Random -Minimum 97 -Maximum 123 [char][byte]$ran } $rca -join ” } The required length is passed as an integer parameter. […]
Return of the missing PSDiagnostics
Posted by: richardsiddaway | December 12, 2018 Comments Off on Return of the missing PSDiagnostics |Return of the missing PSDiagnostics members in PowerShell v6.2 preview 3. In Windows PowerShell v5.1 the PSDiagnostics module contains these members: Disable-PSTrace Disable-PSWSManCombinedTrace Disable-WSManTrace Enable-PSTrace Enable-PSWSManCombinedTrace Enable-WSManTrace Get-LogProperties Set-LogProperties Start-Trace Stop-Trace In PowerShell v6.1.1 you just get these: Disable-PSTrace Enable-PSTrace Get-LogProperties Set-LogProperties Quite a few missing. In PowerShell v6.2 preview 3 we’re […]
Find duplicate characters in a string
Posted by: richardsiddaway | December 12, 2018 Comments Off on Find duplicate characters in a string |Staying with our current theme of manipulating strings this is how you find duplicate characters in a string. function get-duplicatechar { [CmdletBinding()] param ( [string]$teststring ) $teststring.ToCharArray() | Group-Object -NoElement | where Count -gt 1 | Sort-Object -Property Count -Descending } Convert the string to a char array, group on the characters and use […]
Join-String is a new cmdlet in PowerShell v6.2 preview 3. Join-String enables you to use the pipeline to join strings. We’ve had the –join operator for a long time: PS> 1..3 -join ‘,’ 1,2,3 As an alternative you could do PS> 1..3 | Join-String -Separator ‘,’ 1,2,3 You can add a prefix […]
PowerShell v6.2 preview 3 install issue
Posted by: richardsiddaway | December 11, 2018 Comments Off on PowerShell v6.2 preview 3 install issue |PowerShell v6.2 preview 3 install issue – PowerShell v6.2 preview 3 is now available from https://github.com/PowerShell/PowerShell/releases but you may notice a probloem if you install over the top of PowerShell v6.2 preview 2. When you click on the icon to start preview 3 the console will flash open and then immediately close. The fix […]
Categories
- .NET
- Active Directory
- Architecture
- Azure
- Bash
- BITS
- Books
- CDXML
- CIM
- Cloud
- COM
- Containers
- Deep Dive
- Desired State Configuration
- DevOps
- DHCP
- DNS
- DSC
- European Summit
- Events
- Exchange
- File System
- Firewall
- General
- General IT Matters
- Hyper-V
- IIS
- Infrastructure
- IT Community
- IT Security
- Learning PowerShell
- Linux
- Math
- Microsoft
- Modules
- Nano Server
- Networking
- Office 2010
- Office 2013
- Open Source
- Opinion
- Outlook
- Philosophy
- PowerShell
- PowerShell 7
- PowerShell and .NET
- PowerShell and Active Directory
- PowerShell and CIM
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- PowerShell Basics
- PowerShell original
- PowerShell Summit
- PowerShell User Group
- PowerShell User Group 2
- PowerShell v2
- PowerShell V3
- PowerShell v4
- PowerShell v5
- PowerShell v6
- PowerShell.org
- PowerShellGet
- PowerShellV2
- PSAM
- Rant
- Registry
- Scripting
- Scripting Games
- Scripting Games 2104
- Security
- SQL Server
- Storage
- Strings
- Summit
- Technology
- Uncategorized
- Virtualization
- Windows 10
- Windows 2012 R2
- Windows 7
- Windows 8
- Windows 8 Server
- Windows 8.1
- Windows Server
- Windows server 1709
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
- Windows Server 2019
- WMFv5
- WPF
- WSUS