classHelperStuff { # get first character of string and throw exception # when string is empty or multi-line static[char] GetFirstCharacter([string]$Text) { if ($Text.Length -eq0) { throw'String is empty' } if ($Text.Contains("`n")) { throw'String contains multiple lines' } return$Text[0] }
# get file extension in lower case static[string] GetFileExtension([string]$Path) { return [Io.Path]::GetExtension($Path).ToLower() } }
Name Value --------- Extensions [{35378EAC-683F-11D2-A89A-00C04FBBCFA2}{0F6B957E-509E-11D1-A7CC-0000F87571E3}] Link Local Options 0 GPOLink 1 Version 65537 GPOName Guidelines of the local group lParam 0 DSPath LocalGPO FileSysPath C:\WINDOWS\System32\GroupPolicy\Machine DisplayName Guidelines of the local group
# create profile if it does not yet exist $exists = Test-Path-Path$Profile.CurrentUserAllHosts if (!$exists) { $null = New-Item-Path$Profile.CurrentUserAllHosts -ItemType File -Force }
# add code to profile @' $greetings = 'Hello there!', 'Glad to see you!', 'Happy coding!', 'Have a great day!', 'May the PowerShell be with you!' $text = $greetings | Get-Random $null = (New-Object -COM Sapi.SpVoice).Speak($text) '@ | Add-Content-Path$Profile.CurrentUserAllHosts -Encoding Default
$greetings = 'Hello there!', 'Glad to see you!', 'Happy coding!', 'Have a great day!', 'May the PowerShell be with you!'
$greetings | Get-Random
您所需要做的只是将这段代码加到您的 profile 脚本,例如这样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# create profile if it does not yet exist $exists = Test-Path-Path$Profile.CurrentUserAllHosts if (!$exists) { $null = New-Item-Path$Profile.CurrentUserAllHosts -ItemType File -Force }
# add code to profile @' $greetings = 'Hello there!', 'Glad to see you!', 'Happy coding!', 'Have a great day!', 'May the PowerShell be with you!' $greetings | Get-Random '@ | Add-Content-Path$Profile.CurrentUserAllHosts -Encoding Default
When you open a native PowerShell console in Windows 10, you can hold down CTRL+SHIFT, then move your mouse wheel, to adjust console background color transparency, and let other windows shine through. The same works for cmd.exe as well, of course. 当您在 Windows 10 中打开一个原生的 PowerShell 控制台,按下 CTRL + SHIFT 键,然后滚动鼠标滚轮,就可以调节控制台背景色的透明度,并且让其它窗口的内容透射出来。当然这对 cmd.exe 也是有效的。