Another class to execute to get the current user in windows is WindowsIdentity class. It has the GetCurrentname method, which can be used as shown below. ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name).Split('\')[1] ...
# 获取当前登录的用户 $env:USERNAME # 获取计算机名称 $env:COMPUTERNAME # 检查当前用户是否为管理员 ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) # 获取当前用户所属的组列表 $groups = [System...
代码语言:txt 复制 $currentUser = $env:USERNAME 这将返回当前登录用户的用户名。 使用[System.Security.Principal.WindowsIdentity]::GetCurrent().Name获取当前登录用户名: 代码语言:txt 复制 $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name 这将返回当前登录用户的用户名。 以上...
替代PSModulePath此 PowerShell 会话的设置。 如果配置适用于当前用户,则设置CurrentUser模块路径。 如果配置适用于所有用户,则设置AllUsers模块路径。 警告 在此处配置AllUsers或CurrentUser模块路径不会更改 PowerShellGet cmdlet(如Install-Module)的作用域安装位置。 这些 cmdlet 始终使用默认模块路径。
Get-ComputerInfo 英文术语 中文术语 解释 WindowsBuildLabEx Windows 构建实验室扩展 提供操作系统的详细构建信息,通常用于识别 Windows 版本的精确构建号。 WindowsCurrentVersion 当前 Windows 版本 当前 Windows
Get-PSDrive Output 複製 Name Used (GB) Free (GB) Provider Root --- --- --- --- --- Alias Alias C 18.56 107.62 FileSystem C:\ Cert Certificate \ D FileSystem D:\ Env Environment Function Function HKCU Registry HKEY_CURRENT_USER HKLM Registry HKEY_LOCAL_MACHINE Variable Variabl...
$param=@{"DnsName"="mylab.wang.io";"CertStoreLocation"="Cert:\CurrentUser\My";"NotAfter"=(Get-Date).AddYears(10);"KeySpec"="KeyExchange";"KeyExportPolicy"="Exportable";}New-SelfSignedCertificate @param 这段代码创建了一个新的自签名证书,并将其存储在当前用户的 "My" 证书存储中。
以下命令从 $s会话中的远程计算机运行 CurrentUserCurrentHost 配置文件。 由于未填充 $PROFILE 变量,因此该命令使用配置文件的显式路径。 PowerShell 复制 Invoke-Command -Session $s { . "$HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" } 运行此命令后,配置文件添加到会话的命令可在 $...
Hive: HKEY_CURRENT_USER\Software Name Property --- --- MySoftwareKey DefaultFolders : {Home, Temp, Publish} MaxAllowed : 1024 BinaryDate : {51, 49, 45, 74…} 下列範例顯示每種登錄項目的實值類型: PowerShell $key.GetValueNames() |Select-Object@{n='ValueName';e={$_}}, @{n='Value...
Get-ExecutionPolicy-ScopeCurrentUser 更改执行策略 若要更改 Windows 计算机上的 PowerShell 执行策略,请使用Set-ExecutionPolicycmdlet。 更改立即生效。 无需重启 PowerShell。 如果为 ScopesLocalMachine或CurrentUser设置执行策略,更改将保存在配置文件中,并在再次更改之前保持有效。