powershell PowerShell:重新创建LastPass桌面快捷方式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell:重新创建LastPass桌面快捷方式相关的知识,希望对你有一定的参考价值。
[CmdletBinding(SupportsShouldProcess=$True,DefaultParameterSetName="None")]
PARAM(
[switch]$AllUsers
)
begin {
# Adminsitrator role check
function IsLocalAdministrator() {
$CurrentWindowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$CurrentWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($CurrentWindowsIdentity)
$IsInWindowsBuiltInAdministratorRole = $CurrentWindowsPrincipal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
return $IsInWindowsBuiltInAdministratorRole
}
try {
$WshShell = New-Object -ComObject WScript.Shell
} catch {
$_
return
}
$InstallDir = (Get-Item -Path "$env:PROGRAMFILES\LastPass\lastpass.exe" -ErrorAction SilentlyContinue | Select "Directory" -ErrorAction SilentlyContinue).Directory.FullName
if (!$InstallDir) {
$InstallDir = (Get-Item -Path "$env:PROGRAMFILES (x86)\LastPass\lastpass.exe" -ErrorAction SilentlyContinue | Select "Directory" -ErrorAction SilentlyContinue).Directory.FullName
}
if (!$InstallDir) {
# Fake it
$InstallDir = "$env:PROGRAMFILES (x86)\LastPass"
}
}
process {
$BaseFileName = "My LastPass Vault"
$BaseFolder = [Environment]::GetFolderPath("Desktop")
if ($AllUsers -and (IsLocalAdministrator)) {$BaseFolder = [Environment]::GetFolderPath("CommonDesktopDirectory")}
$shortcutPath = Join-Path -Path $BaseFolder -ChildPath "$($BaseFileName).lnk"
try {
$Shortcut = $WshShell.CreateShortcut($shortcutPath)
$Shortcut.TargetPath = "https://lastpass.com/home.php"
$Shortcut.WorkingDirectory = "$InstallDir"
$Shortcut.IconLocation = "$InstallDir\lastpass.exe, 0"
$Shortcut.WindowStyle = 1
$Shortcut.Description = $BaseFileName
} catch {
$_
return
}
try {
$Shortcut.Save()
"Shortcut created successfully ($($shortcutPath))"
return
} catch {
$_
return
}
}
end {
}
以上是关于powershell PowerShell:重新创建LastPass桌面快捷方式的主要内容,如果未能解决你的问题,请参考以下文章
powershell PowerShell:重新创建LastPass桌面快捷方式
powershell SDL Quatron服务使用PowerShell重新启动,启动和停止
powershell SDL Quatron服务使用PowerShell重新启动,启动和停止
PowerShell第一讲,别名,变量,命令。
powershell PowerShell:检查Microsoft / Windows Update是否需要重新启动。安装补丁后即可使用。
通过 WinRM 重新使用 PowerShell 会话