# load module that defines the function: PS C:\> New-TemporaryFile-WhatIf What if: Performing the operation "New-TemporaryFile" on target "C:\Users\tobia\AppData\Local\Temp".
# dump function source code: PS C:\> ${function:New-TemporaryFile}
PS> [System.Globalization.CultureInfo]::GetCultureInfo( 'ru' ).DateTimeFormat.MonthNames Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь
[PSCustomObject]@{ Id = $x+1 English = $english[$x] Russian = $russian[$x] } }
结果类似这样:
Id English Russian
-- ------- -------
1 January Январь
2 February Февраль
3 March Март
4 April Апрель
5 May Май
6 June Июнь
7 July Июль
8 August Август
9 September Сентябрь
10 October Октябрь
11 November Ноябрь
12 December Декабрь
Name DisplayName --------------- aa Afar aa-DJ Afar (Djibouti) aa-ER Afar (Eritrea) aa-ET Afar (Ethiopia) af Afrikaans af-NA Afrikaans (Namibia) af-ZA Afrikaans (South Africa) ...
$startdate = [DateTime]'2022-06-01' $numberOfWeeks = 52 $result = for ($week = 0; $week-lt$numberOfWeeks; $week ++) { # calculate the real date each week $realdate = $startdate + (New-Timespan-days (7*$week))
# calculate the current month $month = $realdate.Month
# calculate the days in this month $daysInMonth = [DateTime]::DaysInMonth($realdate.Year, $realdate.Month)
# make arbitrary adjustments, i.e. set start time to 12PM by default, but 7PM on the last week of a month
# are we in the last week of a month? if ($realdate.Day -gt ($daysInMonth-7)) { # add 19 hours $realdate = $realdate.AddHours(19) } else { # add 12 hours $realdate = $realdate.AddHours(12) }
# create your Excel sheet layout as a CSV file [PSCustomObject]@{ Start = $realdate IsOnline = $false Title = '' Speaker = '' Notes = '' } }
# properties to exclude (add or remove as needed) $blacklist = 'FileList', 'Tags'
$data = Invoke-RestMethod-Uri$url-UseBasicParsing | ForEach-Object { $hash = [Ordered]@{} $moduleInfo = $_.Properties foreach($_in$moduleInfo.PSObject.Properties) { # name of property $name = $_.Name # if it is in blacklist, skip and continue with next property if ($name-in$blacklist) { continue } # if it is the property "name", then skip # all remaining (xml default properties) if ($name-eq'Name') { break }
# if type is "xmlelement", retrieve underlying text value in #text if ($_.TypeNameOfValue -eq'System.Xml.XmlElement') { $hash[$name] = $moduleInfo.$name.'#text'
# if a datatype is assigned, try and convert to appropriate type if ($moduleInfo.$name.type -like'Edm.*') { $typename = $moduleInfo.$name.type.replace('Edm.','') $hash[$name] = $hash[$name] -as$typename } } else { $hash[$name] = $_.Value } }
# convert a hash table to object and return it [PSCustomObject]$hash }
# determine the primary module location for your PowerShell version $path = if ('Management.Automation.Platform'-as [Type]) { # PowerShell CLR if ([Environment]::OSVersion.Platform -like'Win*'-or$IsWindows) { # on Windows Join-Path-Path$env:ProgramFiles-ChildPath'PowerShell' } else { # on Non-Windows $name = [Management.Automation.Platform]::SelectProductNameForDirectory('SHARED_MODULES') Split-Path-Path$name-Parent } } else { # Windows PowerShell Join-Path-Path$env:ProgramFiles-ChildPath"WindowsPowerShell" }
在 Windows 上,PowerShell 7 和 Windows PowerShell 可以共享一个文件夹,因此如果您不想专门为 PowerShell 7 部署模块,则可以进一步简化脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# determine the primary module location for your PowerShell version $path = if ([Environment]::OSVersion.Platform -like'Win*'-or$IsWindows) { # Windows Join-Path-Path$env:ProgramFiles-ChildPath"WindowsPowerShell" } else { # Non-Windows $name = [Management.Automation.Platform]::SelectProductNameForDirectory('SHARED_MODULES') Split-Path-Path$name-Parent }