# search for the module in PowerShell Gallery (optional) PS> Find-Module-Name Microsoft.Online.SharePoint.PowerShell
Version Name Repository Description ----------------------------- 16.0.19927.12000 Microsoft.Online.SharePoint.Powe... PSGallery Microsoft SharePoint Online
# install the module in your personal scope (no admin privileges required) PS> Install-Module-Name Microsoft.Online.SharePoint.PowerShell -Repository PSGallery -Scope CurrentUser
# take a SecureString and get the entered plain text password # we are using a SecureString only to get a masked input box $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# fails: PS> Test-Password-Password test Test-Password : Cannot process argument transformation on parameter'Password'. Cannot convert the "test" value of type"System.String" to type"System.Security.SecureString".
# works PS> Test-Password-Password ("test" | ConvertTo-SecureString-AsPlainText-Force) You entered: test
# take a SecureString and get the entered plain text password # we are using a SecureString only to get a masked input box $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# use built-in masked input PS> Test-Password cmdlet Test-Password at command pipeline position 1 Supply values for the following parameters: Password: ****** You entered: secret
# use text-to-SecureString transformation attribute PS> Test-Password-Password secret You entered: secret
# take securestring and get the entered plain text password # we are using a securestring only to get a masked input box $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# separate the first 5 hash characters from the rest $first5hashChars,$remainingHashChars = $hash.Hash -split'(?<=^.{5})'
# send the first 5 hash characters to the web service $url = "https://api.pwnedpasswords.com/range/$first5hashChars" [Net.ServicePointManager]::SecurityProtocol = 'Tls12' $response = Invoke-RestMethod-Uri$url-UseBasicParsing
# split result into individual lines... $lines = $response-split'\r\n' # ...and get the line where the returned hash matches your # remainder of the hash that you kept private $filteredLines = $lines-like"$remainingHashChars*"
# return the number of compromises [int]($filteredLines-split':')[-1] }
Windows 注册表存储已安装的所有软件的名称和详细信息。PowerShell 可以读取该信息,并为您提供完整的软件清单:
1 2 3 4 5 6 7 8 9 10 11 12
# read all child keys (*) from all four locations and do not emit # errors if one of these keys does not exist Get-ItemProperty-Path'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*', 'HKCU:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'-ErrorAction Ignore | # list only items with the DisplayName Where-Object DisplayName | # show these registry values per item Select-Object-Property DisplayName, DisplayVersion, UninstallString, InstallDate | # sort by DisplayName Sort-Object-Property DisplayName
CommandType Name Version Source ---------------------------- FunctionNew-PSOneQRCodeGeolocation2.2QRCodeGenerator FunctionNew-PSOneQRCodeTwitter2.2QRCodeGenerator FunctionNew-PSOneQRCodeVCard2.2QRCodeGenerator FunctionNew-PSOneQRCodeWifiAccess2.2QRCodeGenerator
Version Name Repository Description -------------------------------- 2.2.3 PowerShellGet PSGallery PowerShell module with commands for discovering, installing, upd...
If you own Administrator privileges, you can even change this setting. To turn off automatic reset booting, run this: 如果您拥有管理员特权,甚至可以更改此设置。要关闭自动重置启动,请运行以下命令:
1
Set-CimInstance-Query'Select * From Win32_ComputerSystem'-Property@{AutomaticResetBootOption=$false}
classValidatePathExistsAttribute : System.Management.Automation.ValidateArgumentsAttribute { # the value to be checked surfaces in $path and must be of type [object] [void]Validate([object]$path, [System.Management.Automation.EngineIntrinsics]$engineIntrinsics) { # if anything is wrong with the value, throw an exception if([string]::IsNullOrWhiteSpace($path)) { Throw [System.ArgumentNullException]::new() } if(-not (Test-Path-Path$path)) { Throw [System.IO.FileNotFoundException]::new() }
# if NO exception was thrown, the value is accepted } } #endregion