|
932 | 932 | "Category": 8,
|
933 | 933 | "ExpiryDate": "9999-12-31T23:59:59.9999999",
|
934 | 934 | "Author": "Daniel Schroeder (deadlydog)"
|
| 935 | + }, |
| 936 | + { |
| 937 | + "CreatedDate": "2025-04-18T00:00:00", |
| 938 | + "Title": "Capture superfluous parameters passed to your function(s)", |
| 939 | + "TipText": "Capture any parsed parameter to prevent a function from bombing out when being passed unknown / misspelled variables.\r\nComes in handy when parsing the $PSBoundParameters from a calling script with just a subset of parameters that are appropriate / needed by your (custom) function.", |
| 940 | + "Example": "[CmdletBinding()]\r\nparam(\r\n[Parameter(DontShow, ValueFromRemainingArguments)]$Superfluous\r\n)\r\n\r\nWrite-Verbose -Message \"Ignoring superfluous params: $($Superfluous -join ' ')\"", |
| 941 | + "Urls": [ |
| 942 | + "https://github.com/ChristelVDH/SyncAD2AAD/blob/main/ConnectTo-Graph.ps1", |
| 943 | + "https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.parameterattribute.valuefromremainingarguments", |
| 944 | + "https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.parameterattribute.dontshow" |
| 945 | + ], |
| 946 | + "Category": 6, |
| 947 | + "ExpiryDate": "9999-12-31T23:59:59.9999999", |
| 948 | + "Author": "Christel VdH" |
| 949 | + }, |
| 950 | + { |
| 951 | + "CreatedDate": "2025-04-29T00:00:00", |
| 952 | + "Title": "Use Measure-Object to get stats about objects", |
| 953 | + "TipText": "You can use the Measure-Object cmdlet to get statistics about objects in PowerShell. This cmdlet can be used to calculate the sum, average, minimum, maximum, and count of numeric properties in objects. When used with text input, it can count characters, words, and lines.\r\n\r\nThe cmdlet returns an object containing properties for each statistic, but the statistic is only actually calculated if you provided the switch for it. For example, if you only provide the -Sum switch, the Sum property will contain the sum of the values, but the Average property will be null since the -Average switch was not provided.", |
| 954 | + "Example": "# Get all statistics about a range of numbers.\r\n1..10 | Measure-Object -Average -Sum -Minimum -Maximum -StandardDeviation\r\n\r\n# Get all statistics about a string.\r\n\"Hello there\" | Measure-Object -Character -Word -Line\r\n\r\n# Count the number of words in a file.\r\nGet-Content 'C:\\path\\to\\file.txt' | Measure-Object -Word\r\n\r\n# Calculate the total size (Length) of all files in the current directory.\r\nGet-ChildItem | Measure-Object -Property Length -Sum\r\n\r\n# In an array of objects, find the one with the maximum value of the Num property.\r\n@{num=3}, @{num=4}, @{num=5} | Measure-Object -Maximum Num\r\n\r\n# Get the total and maximum CPU time and paged memory size of all processes.\r\nGet-Process | Measure-Object -Property CPU,PagedMemorySize -Sum -Maximum", |
| 955 | + "Urls": [ |
| 956 | + "https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/measure-object", |
| 957 | + "https://adamtheautomator.com/powershell-measure-object/" |
| 958 | + ], |
| 959 | + "Category": 3, |
| 960 | + "ExpiryDate": "9999-12-31T23:59:59.9999999", |
| 961 | + "Author": "Daniel Schroeder (deadlydog)" |
| 962 | + }, |
| 963 | + { |
| 964 | + "CreatedDate": "2025-05-05T00:00:00", |
| 965 | + "Title": "Use Join-Path and Split-Path to create cross-platform paths", |
| 966 | + "TipText": "When creating file paths in PowerShell, use the `Join-Path` cmdlet instead of string concatenation. This ensures that the correct path separator is used for the current platform (e.g. `\\` on Windows and `/` on Linux/macOS). PowerShell 6 introduced the -AdditionalChildPath parameter, which allows you to specify multiple child paths to join.\r\n\r\nSimilarly, you can use the `Split-Path` cmdlet to split a path into its components. This is useful for extracting the directory or file name from a full path.", |
| 967 | + "Example": "# Don't do this, as it may not work on all platforms.\r\n[string] $configFilePath = \"$HOME/Config/config.json\"\r\n\r\n# Do this instead, as it works on all platforms.\r\n[string] $configDirectoryPath = Join-Path -Path $HOME -ChildPath 'Config'\r\n[string] $configFilePath = Join-Path $configDirectoryPath 'config.json' # Excludes -Path and -ChildPath for brevity.\r\n\r\n# You can use System.IO.Path to easily join multiple paths. Helpful in Windows PowerShell.\r\n[string] $configFilePath = [System.IO.Path]::Combine($HOME, 'Config', 'config.json')\r\n\r\n# In PowerShell 6+ you can join multiple child paths at once using -AdditionalChildPath.\r\n[string] $configFilePath = Join-Path -Path $HOME -AdditionalChildPath 'Config' 'config.json'\r\n[string] $xmlFilePath = Join-Path $HOME 'Config' 'config.xml' # Excludes parameter names for brevity.\r\n\r\n# Use -Resolve to ensure we get an absolute path, and error if the path does not exist.\r\n[string] $configFilePath = Join-Path $HOME 'Config' 'config.json' -Resolve\r\n\r\n# Get the name of the file with and without the extension, it's parent directory path, and it's parent directory name.\r\n[string] $fileName = Split-Path -Path $configFilePath -Leaf\r\n[string] $fileNameWithoutExtension = Split-Path -Path $configFilePath -LeafBase\r\n[string] $directoryPath = Split-Path -Path $configFilePath -Parent\r\n[string] $directoryName = Split-Path -Path $directoryPath -Leaf\r\n\r\n# Change the working directory to the folder containing your PowerShell profile.\r\nSet-Location (Split-Path -Path $PROFILE)", |
| 968 | + "Urls": [ |
| 969 | + "https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/join-path", |
| 970 | + "https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/split-path" |
| 971 | + ], |
| 972 | + "Category": 3, |
| 973 | + "ExpiryDate": "9999-12-31T23:59:59.9999999", |
| 974 | + "Author": "Daniel Schroeder (deadlydog)" |
| 975 | + }, |
| 976 | + { |
| 977 | + "CreatedDate": "2025-09-03T00:00:00", |
| 978 | + "Title": "Array Lists", |
| 979 | + "TipText": "An Array list is similar to an array, but it does not have a fixed size like an array does.\r\n\r\nWith a fixed-sized array and you add an item to the array, the array is actually recreated with the additional item. This can impact performance, when working with thousands of items.\r\n\r\nAnother concern with fixed-size arrays is that there's no simple method to remove an item.", |
| 980 | + "Example": "# In PowerShell, you can create an Array list using the `System.Collections.ArrayList` class. Here's how you can create and use an Array list:\r\n\r\n[System.Collections.ArrayList]$computers = @('Server1', 'Server2', 'Server3')\r\n\r\n# To create an empty array ready to add items\r\n\r\n$computers=New-Object System.Collections.ArrayList", |
| 981 | + "Urls": [ |
| 982 | + "https://learn.microsoft.com/en-us/training/modules/work-arrays-hash-tables-window-powershell-scripts/3-work-array-lists-windows", |
| 983 | + "https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-arrays?view=powershell-7.5#arraylist" |
| 984 | + ], |
| 985 | + "Category": 4, |
| 986 | + "ExpiryDate": "9999-12-31T23:59:59.9999999", |
| 987 | + "Author": "Adrian Muscat (adrimus)" |
| 988 | + }, |
| 989 | + { |
| 990 | + "CreatedDate": "2025-09-20T00:00:00", |
| 991 | + "Title": "Adjust tiPS display frequency", |
| 992 | + "TipText": "You can adjust how often tips are automatically shown by using the `Set-TiPSConfiguration` command.\r\n\r\nIf you find that you are seeing the same tips over and over, it means that you've viewed all of the tips currently in the tiPS module.\r\nWhile new tips do get added to the module over time, you may want to adjust how often tips are shown, such as changing the frequency from Daily to Weekly.\r\n\r\nBy default, tips are shown from newest to oldest, so even if you reduce the frequency you will still see newly added tips next.", |
| 993 | + "Example": "Set-TiPSConfiguration -AutomaticallyWritePowerShellTip Biweekly", |
| 994 | + "Urls": [ |
| 995 | + "https://github.com/deadlydog/PowerShell.tiPS?tab=readme-ov-file#-commands" |
| 996 | + ], |
| 997 | + "Category": 2, |
| 998 | + "ExpiryDate": "9999-12-31T23:59:59.9999999", |
| 999 | + "Author": "Daniel Schroeder (deadlydog)" |
| 1000 | + }, |
| 1001 | + { |
| 1002 | + "CreatedDate": "2025-09-20T00:00:00", |
| 1003 | + "Title": "Use Get-Verb to see approved verbs", |
| 1004 | + "TipText": "Use the Get-Verb cmdlet to see a list of all approved verbs in PowerShell. This is useful when creating your own functions or cmdlets, as using approved verbs helps ensure consistency and discoverability. You know right away what a function does simply by the verb it uses.\r\n\r\nGet-Verb is also great for learning about new verbs you may not have known about, including the typical alias abbreviations.", |
| 1005 | + "Example": "# List all approved verbs and their descriptions.\r\nGet-Verb", |
| 1006 | + "Urls": [ |
| 1007 | + "https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-verb", |
| 1008 | + "https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands" |
| 1009 | + ], |
| 1010 | + "Category": 3, |
| 1011 | + "ExpiryDate": "9999-12-31T23:59:59.9999999", |
| 1012 | + "Author": "Daniel Schroeder (deadlydog)" |
935 | 1013 | }
|
936 | 1014 | ]
|
0 commit comments