$currentUser = $env:USERNAME 这将返回当前登录用户的用户名。 使用[System.Security.Principal.WindowsIdentity]::GetCurrent().Name获取当前登录用户名: 代码语言:txt 复制 $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name ...
Get-LocalUser -Name "User1" | ConvertTo-Json 输出会是类似的 JSON 格式: jsonCopy Code { "Name": "User1", "Enabled": true, "Description": "User account" } 4. 输出格式的深度控制 ConvertTo-Json 命令默认将输出数据转换为 2 层深度。如果你需要更深层次的嵌套结构(例如对象中包含对象),可以使...
读取$name里的内容:$name[0].DisplayName :表示获取第一行,Displayname字段的值。 write host 输出 powershell支持模糊查询,通配符: * 如下:get-user -identity "zhangchuanlei*" 1. 2. 3. 4. 5. Get-User -identity "test" | select * //查询返回该账号的 所有字段信息 1....
Get-User -Filter "Title -like 'Manager*'" 此範例會使用 Filter 參數來擷取其職稱結尾有文字 Manager 的所有使用者相關資訊。 參數 -Anr Anr 參數會指定用來執行模糊名稱解析 (ANR) 搜尋的字串。 您可以指定部分字串,然後搜尋屬性符合該字串的物件。 搜尋的預設屬性如下: CommonName (CN) DisplayName First...
使用Get-UserPrincipalNamesSuffix cmdlet 可以查看 Active Directory 林中的用户主体名称 (UPN) 后缀。 UPN 后缀在 Active Directory 域和信任中创建。 有关以下语法部分的参数设置的详细信息,请参阅 Exchange cmdlet 语法。 语法 PowerShell 复制 Get-UserPrincipalNamesSuffix [-OrganizationalUnit <ExtendedOrganizatio...
Get -LocalUser 是 PowerShell 的一个命令行工具,用于查询本地计算机上创建的用户账户。这个命令可以帮助系统管理员查看所有本地用户账户的信息,如用户名、密码复杂度要求、账户类型等。用法 主要参数的作用 -Name : 指定要查询的用户账户名称。如果不指定名称,将返回所有本地用户账户的信息。示例 1. 获取...
# Connect to Microsoft GraphConnect-Graph-ScopesUser.ReadBasic.All 查看所有帐户 若要显示具有用户 ID 和用户主体名称的用户帐户的完整列表,请运行以下命令: PowerShell Get-MgUser-All| Select DisplayName,Id,UserPrincipalName 应获取类似于以下内容的信息: ...
我对用PowerShell实现自动化部署也有了一些心得,比如说利用PowerShell导出导入AD中的User。
.idNew-MgDirectoryRole-DisplayName$roleName-RoleTemplateId$roleTemplate$role=Get-MgDirectoryRole|Where-Object{$_.displayName-eq$roleName} }$userId= (Get-MgUser-Filter"userPrincipalName eq '$userUPN'").Id$newRoleMember=@{"@odata.id"="https://graph.microsoft.com/v1.0/users/$userId"}New-...
$Secure=Read-Host-AsSecureString$Encrypted=ConvertFrom-SecureString-SecureString$Secure-Key(1..16)$Encrypted|Set-ContentEncrypted.txt ...$Secure2=Get-ContentEncrypted.txt |ConvertTo-SecureString-Key(1..16)Connect-UPService-UserPrincipalNameusername@tenantname.com-Password$Secure2 ...