mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
M365

PowerShellでローカルアカウントの操作

https://www.vwnet.jp/Windows/PowerShell/MaintenanceLocalAccunt.htm ドメイン環境であればアカウント メンテナンス用の PowerShell コマンドレットが数多く提供されていますが、ワークグループ環境で使うローカルアカウントにはメンテナンス コマンドレットが用意されていません。 結構困るので、良く使う「アカウント新規作成」「グループへ参加」「パスワード無期限設定」「パスワード更新」を関数にしました。 メンバーになっているかの確認も必要なので、メンバーか否かの確認関数も作ってみました。 組み込みで使う事を想定していますが、関数コピペして使う事も出来ます。 ################################################ # アカウント新規作成 ################################################ function CreateUser( $UserID, $Password ){     $hostname = hostname     [ADSI]$Computer = "WinNT://$hostname,computer"     $NewUser = $Computer.Create("User", $UserID)     $NewUser.SetPassword( $Password )     $NewUser.SetInfo() } ################################################ # グループへ参加 ################################################ function JoinGroup( $UserID, $JoinGroup ){     $hostname = hostname     [ADSI]$Computer = "WinNT://$hostname,computer"     $Group = $Computer.GetObject("group", $JoinGroup)     $Group.Add("WinNT://$hostname/$UserID") } ######################################################################################## # グループへ参加 #  IIS APPPOOL\xx とかの一般的なユーザーではないアカウントとローカルグループ追加対応 ######################################################################################## function JoinGroup2( $UserID, $JoinGroup ){     $hostname = hostname     $Group = [ADSI]"WinNT://$hostname/$JoinGroup,group"     $NTAccount = New-Object System.Security.Principal.NTAccount($UserID)     $SID = $NTAccount.Translate([System.Security.Principal.SecurityIdentifier])     $User = [ADSI]"WinNT://$SID"     $Group.Add($User.Path) } ################################################ # パスワード無期限設定 ################################################ function DontExpirePasswd( $UserID ){     $hostname = hostname     [ADSI]$UpdateUser = "WinNT://$HostName/$UserID,User"     $UserFlags = $UpdateUser.Get("UserFlags")     $UserFlags = $UserFlags -bor 0x10000     $UpdateUser.Put("UserFlags", $UserFlags)     $UpdateUser.SetInfo() } ################################################ # パスワード更新 ################################################ function UpdatePasswd( $UserID, $Password ){     $hostname = hostname     [ADSI]$UpdateUser = "WinNT://$HostName/$UserID,User"     $UpdateUser.SetPassword( $Password )     $UpdateUser.SetInfo() } ################################################ # ローカルユーザーが存在するか ################################################ function IsLocalUserAccunt( $UserID ){     $hostname = hostname     [ADSI]$Computer = "WinNT://$hostname,computer"     $Users = $Computer.psbase.children | ? {$_.psBase.schemaClassName -eq "User"} | Select-Object -expand Name     return ($Users -contains $UserID) } ################################################ # ドメインユーザーが存在するか ################################################ function IsADUserAccunt( $DomainName, $DomainUser ){     $hostname = hostname     $ADUser = [ADSI]("WinNT://$DomainName/$DomainUser")

2019-05-20 0comments 111hotness 0likes mikebai Read all
M365

ps Invoke note

$de = New-Object System.DirectoryServices.DirectoryEntry('WinNT://./Administrators,group') "Group: " + $de.Name "GroupPath: " + $de.Path $de|Get-Member $de.psbase|Get-Member @($de.psbase.Invoke("Members"))

2019-05-20 0comments 110hotness 0likes mikebai Read all
M365

PowerShell ADSI(PowerShell – 活动目录)

https://blog.51cto.com/57388/1647339 1.PowerShell 可以实现对ADSI(Active Directory Service Interface)服务接口的支持; 2.ADSI类似于Windows 管理规范(WMI),发出一个使用特殊语法编写的查询,然后传递给远程计算机(域控制器),然后执行它。查询结果为一个AD对象或对象的集合(如一个用户或用户组),并且你可以获得该对象的引用;修改保存,创建,删除对象; 3.使用Windows PowerShell 管理活动目录的必要条件; a)至少有一个基于web服务活动目录的域控制器;(AD WS),运行于Windows 2008 R2 b)或管理网关服务活动目录的域控制器;(AD MGS),运行在Windows 2003 和2008 c)如果是AD web服务,由于他不支持老的客户端(windows XP, Vista 等等), 你必要有windows 7, 或windows server 2008 r2 客户端 活动目录PowerShell cmdlet查询流程; a)[Client] cmdlet -> AD WS -> Query DC -> AD WS -> cmdlet. b)cmdlet或客户端使用它们自己的协议做域询问并发送询问到AD Web服务。 c)然后域控器(DC)制作反应通过AD Web服务发回到“客户”,并且这些信息都封装在网服务协议中。

2019-05-20 0comments 113hotness 0likes mikebai Read all
M365

Working with SIDs

Windows PowerShell Tip of the Week 06/08/2010 4 minutes to read Here’s a quick tip on working with Windows PowerShell. These are published every week for as long as we can come up with new tips. If you have a tip you’d like us to share or a question about how to do something, let us know. Find more tips in the Windows PowerShell Tip of the Week archive. Working with SIDs

2019-05-17 0comments 122hotness 0likes mikebai Read all
M365

语法 – “@”符号在Powershell中做什么?

我看到了在PowerShell中使用的@符号来初始化数组。 @符号是什么意思,我在哪里可以阅读更多? 最佳答案 PowerShell实际上会将任何逗号分隔的列表视为数组: “server1”,“server2” 所以在这些情况下@是可选的。但是,对于关联数组,@是必需的: @ {“Key”=“Value”;“Key2”=“Value2”} 官方来说,@是“数组运算符”。您可以在与PowerShell一起安装的文档中或者在我共同创作的“Windows PowerShell:TFM”这样的书中阅读更多信息。

2019-05-17 0comments 112hotness 0likes mikebai Read all
M365

PowerShell中百分号(%)的含义

关键词 PowerShell中百分号(%)的含义 摘要 PowerShell中百分号(%)的含义 在PowerShell代码中,我们经常会看到如下的代码: PS C:\Users\zhanghong> Get-Childitem d:\ | % {$_.Name} 这里的$_表示循环变量,之前洪哥介绍过。可以通过这个链接了解相关信息:<#ZC_BLOG_HOST#>post/powershell-loop-variant-operator.html PowerShell中百分号(%)的含义 在PowerShell代码中,我们经常会看到如下的代码: PS C:\Users\zhanghong> Get-Childitem d:\ | % {$_.Name} 这里的$_表示循环变量,之前洪哥介绍过。可以通过这个链接了解相关信息:<#ZC_BLOG_HOST#>post/powershell-loop-variant-operator.html 接下来,我们看看这个百分号(%),百分号后面有一对大括号({}),大括号中是一个变量表达式。 这段代码的作用是先获取所有的D:\目录下的子对象,包括所有的文件和文件夹。然后将这些对象输出到下一条语句。 百分号(%),是一个循环语句,它是ForEach-Object的别名。“% {$_.Name}”语句的作用就是循环输出所有的对象了名称。  

2019-05-17 0comments 119hotness 0likes mikebai Read all
M365

Linux shell中的竖线(|)——管道符号

管道符号,是unix一个很强大的功能,符号为一条竖线:"|"。 用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为command 2的输入传给command 2,例如: $ls -s|sort -nr (请注意不要复制$符号进去哦) -s 是file size,-n是numeric-sort,-r是reverse,反转 该命令列出当前目录中的文档(含size),并把输出送给sort命令作为输入,sort命令按数字递减的顺序把ls的输出排序。 $ls -s|sort -n 按从小到大的顺序输出。 当然还可进行多次操作,如下面的功能为先去除纯数字,再由sed将竖线(这里不是管道符号)替换为空格,再将结果取出来排序,再进行结果的选择显示,不明白可查看 排序和分页。 cat filename |grep -v '^[0-9]*$' | sed 's/|/ /g' |sort -nrk 8 -nrk 9 |tail -n +1 |head -n 10

2019-05-17 0comments 112hotness 0likes mikebai Read all
M365

Powershell change default variable scope in script

https://stackoverflow.com/questions/29409104/powershell-change-default-variable-scope-in-script Is there an option to change the default variable scope to private for a script? E.g. via PSDefaultParameterValues? I don't like that variables are used from parent when they are note defined in the current scope. Set

2019-05-16 0comments 118hotness 0likes mikebai Read all
M365

About powsershell variable Scopes

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-6 09/04/2018 13 minutes to read Contributors      

2019-05-16 0comments 114hotness 0likes mikebai Read all
M365

Change the PowerShell MachinePolicy Execution Policy

FROM: https://absolute-sharepoint.com/2014/03/change-powershell-machinepolicy-execution-policy-windows-server-2012r2.html Background Last week I wanted to try the new SharePoint 2013 SP1 and, as I never install SharePoint without using PowerShell scripts, I tried using the awesome AutoSPInstaller to install my SharePoint. When Windows Server 201 R2 came out, the twitter sphere said that nothing changed except the Execution Policy was “RemoteSigned”. AutoSPInstaller has a Launch.bat file that makes sure the Main.ps1 launches in “ByPass” mode. However, the way AutoSPInstaller works is that it includes two other PowerShell files where the functions are stored. When those get included, the ByPass mode is not in effect anymore, and PowerShell goes back to the Machine Policy, which by default is Remote Signed. It’s a good security measure, but we need to get this fixed! Also for the sake of Google indexing the error for other people, here is the error text: File cannot be loaded. The file is not digitally signed. You cannot run this script on the current system. So, I tried to change the execution policy from Powershell with the following command:

2019-04-19 0comments 127hotness 0likes mikebai Read all
1…1617181920…62

Recent Posts

  • c# winform适配高dpi
  • com.microsoft.sqlserver.jdbc.SQLServerException “trustServerCertificate”属性设置为“false”,但驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server建立安全连接
  • java -cp 用法介绍
  • HTML 容器元素
  • MVC的cshtml的介绍

Recent Comments

No comments to show.

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang