Chef Windows: 创建Windows用户时创建主目录

Chef Windows: Create the home directory when creating Windows User

我正在尝试使用以下代码创建用户并自动创建主目录

user "username" do 
   supports :manage_home => true
   comment "ChefUser"
   home "C:\Users\username"
   password "somepassword"
   action :create
end

下面的代码也不起作用。它给出了错误 "Error: NoMethodError: undefined method each_char for #array:0x4434

user "username" do 
   supports :manage_home => true
   comment "ChefUser"
   home "C:\Users\username"
   password "somepassword"
   action :create
   provider Chef::Provider::User::Useradd
end

我这里做错了什么。

引用to documentation:

When the Windows provider is used, Microsoft Windows does not create a home directory for a user until that user logs on for the first time; specifying the home directory does not have any effect as to where Microsoft Windows ultimately places the home directory.

听起来像是 XY 问题。

我怀疑您希望创建使用目录来为您的用户设置一些设置或文档。

在 windows 中,实现此目的的实际方法是使用 default userall users 主目录。

All Users 的内容将与工作站上的每个用户目录合并(即:放置在 All Users\Desktop 的快捷方式将在每个用户桌面上,他们无法删除它,有用用于支持 link 或所有用户共享的其他部分)

Default User的内容是用户主目录模板,在用户第一次连接时,将通过复制Default User目录(包括桌面上的快捷方式、我的文档目录中的文档等)

因此,您的案例的答案更多是在 Default UserAll Users 路径上工作,而不是尝试创建和在每个用户主目录上工作。如果您希望为每个用户设置特定的脚本,请在脚本中使用 %USERNAME%%USERPROFILE% 来获取用户名及其配置文件目录。