Get-User -Identity "Coy Damon" | Format-List 此範例會傳回名為 Coy Damon 之用戶的詳細資訊。 範例3 PowerShell 複製 Get-User -OrganizationalUnit "Marketing" 此範例會擷取行銷 OU 中的使用者相關資訊。 範例4 PowerShell 複製 Get-User -Filter "Titl
$userList=Get-ADUserkevmarif($null-ne$userList){...} 我更喜欢使用if或foreach,而不是使用try/catch。 别误会,我仍然会大量使用try/catch。 但是,如果我可以测试错误条件或空结果集,我可以允许我的异常处理适用于真正的异常。 我倾向于在对某个对象的值进行索引或调用方法之前,先检查$null。 这两个动作...
Get-User-Identity"Coy Damon"|Format-List This example returns detailed information for the user named Coy Damon. Example 3 PowerShell Get-User-OrganizationalUnit"Marketing" This example retrieves information about users in the Marketing OU.
首次使用PowerShellGet模块中的某个命令时,系统会提示你安装 NuGet 提供程序。 若要安装MrToolkit模块,请通过管道将上一个命令传递给Install-Module。 PowerShell Find-Module-NameMrToolkit |Install-Module-ScopeCurrentUser Output Untrusted repository You are installing the modules from an untrusted repository. If...
userPrincipalName =$dbu.$db_user_principal_name_column_namepasswordProfile = @{ Password =-join(((48..90) + (96..122)) *16|Get-Random-Count16| % {[char]$_}) } }try{New-MgUser-BodyParameter$params} catch {$dbu_creation_failed_list+=$dbu;throw} }else{$dbu_missing_columns_list...
此示例演示如何创建与 Get-Credential返回的凭据对象相同的凭据对象。 PowerShell 复制 $User = "Domain01\User01" $PWord = Read-Host -Prompt 'Enter a Password' -AsSecureString $credentialParams = @{ TypeName = 'System.Management.Automation.PSCredential' ArgumentList = $User, $PWord } $Credential...
# 获取注册表项的权限 Get-Acl -Path "HKCU:\Software\MyApp" | Format-List # 设置注册表项的权限 $acl = Get-Acl -Path "HKCU:\Software\MyApp" $permission = "DOMAIN\User","ReadKey","Allow" $accessRule = New-Object System.Security.AccessControl.RegistryAccessRule($permission) $acl.SetAccess...
Get-WinEventcmdlet 从计算机获取日志信息。ListLog参数使用星号 (*) 通配符来显示有关每个日志的信息。 示例2:获取经典安装日志 此命令获取表示经典安装程序日志的EventLogConfiguration对象。 该对象包括有关日志的信息,例如文件大小、提供程序、文件路径以及是否启用日志。
Get-Item Get-ItemProperty Get-ItemPropertyValue Get-Location Get-Process Get-PSDrive Get-PSProvider Get-Service Get-TimeZone Invoke-Item Join-Path Move-Item Move-ItemProperty New-Item New-ItemProperty New-PSDrive New-Service Pop-Location Push-Location ...
Get-EventLog -LogName System -EntryType Error //检测到系统错误 【获取登录信息】 gwmi Win32_LoggedOnUser //成功登录的记录 gwmi Win32_LoggedOnUser | ft Antecedent //成功登录的用户 【开关机相关】 Stop-Computer //关机 Restart-Computer //重启 ...