【备忘】日常运维常用命令

1. 批量远程修复DNS注册:
* foreach ($pc in $pcs) {.\psexec \\$pc -s "c:\windows\system32\ipconfig.exe" /registerdns}

2. 日历权限管理:
* Get-MailboxFolderPermission -Identity "[email protected]:\calendar"
* Remove-MailboxFolderPermission -Identity "[email protected]:\calendar" -User "u, co"
* Set-MailboxFolderPermission -Identity [email protected]:\Calendar -User [email protected] -AccessRights Editor -SharingPermissionFlags Delegate -SendNotificationToUser $true

3. 获取AAD用户信息:
Get-AzureADUser -all $true | ?{$_.displayname -like "o, M"}

4. 设置MSOL里用户的使用地 (UsageLocation): 
* get-msoluser -UserPrincipalName [email protected] | fl usagelocation,country
UsageLocation : CN
Country       : China

* get-msoluser -All | ft userprincipalname,usagelocation,country >> .\usagelocation.txt

> $users = Get-Content .\temp.txt
> foreach ($u in $users) {
Get-MsolUser -UserPrincipalName $u | set-msoluser -UsageLocation "CN"
}

5。设置邮箱FA权限:
* Add-MailboxPermission -Identity "cc" -User "o, k" -AccessRights FullAccess -InheritanceType All

6. 管理邮箱的SendAs权限:
* Remove-RecipientPermission -Identity [email protected] -AccessRights sendas -Trustee S-1-5-21-...

7. 查看目录Owner:
* GET-ACL

8. 获取清单,利用Powershell逐个处理:
* $Users = Import-Csv "FileSystem::\\server\share\P\User.csv" | foreach { Get-*** | fl }

9. 获取设备上次启动时间:
- (gcim Win32_OperatingSystem).LastBootUpTime
- 变通一下,获取自上次重启后的运行时间:$uptime = (get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

10. Win10、 Server2016/19 安装中文语言包
- 先从微软网站获取离线语言包安装文件
- 运行 DISM  /online /add-package /packagepath=d:\temp\lp.cab 进行安装
- 系统设置里调整语言、地区等属性。
- 重启

11. Setspn -Q spnName    --查询指定的SPN(需要知道SPN 名)
PS C:\> setspn -Q HTTP/WIN-PT4FFE        #HTTP/WIN-PT4FFESPN
Checking domain DC=cn-prod,DC=aaa,DC=com
CN=rs_uat,OU=...,DC=com
    http/WIN-PT4FFE.cn-prod.aaa.com
    http/WIN-PT4FFE
    http/WIN-PT4FFE.cn-prod.aaa.com\PBIRS

12. Setspn -L targetAccountName    --查看对应账号下注册的SPN(需要知道账号名)
PS C:\users\desktop> setspn -L rs_uat      # rs_uat 是服务账号名
Registered ServicePrincipalNames for CN=rs_uat,OU=...,DC=aaa,DC=com:
    http/WIN-PT4FFE
    http/WIN-PT4FFE.cn-prod.aaa.com
    http/WIN-PT4FFE.cn-prod.aaa.com\PBIRS

13. 远程启用Windows 功能, 以Telnet客户端为例
CMD: psexec \\computername dism /online /Enable-Feature /FeatureName:TelnetClient
PS: enter-pssession computername, 然后运行:Install-WindowsFeature -name "Telnet-Client"

14. 安装 Powershell 模块时, 报错:  
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.

解决:
先运行命令: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

15. 使用随机数作为PS命令所生成文件的文件名
dir  | out-file ((random(100)).tostring()+".txt")

猜你喜欢

转载自blog.csdn.net/aladinggao/article/details/119607469