Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell Active Directory登录脚本自动生成_Powershell_Active Directory_Powershell 4.0 - Fatal编程技术网

PowerShell Active Directory登录脚本自动生成

PowerShell Active Directory登录脚本自动生成,powershell,active-directory,powershell-4.0,Powershell,Active Directory,Powershell 4.0,我已经使用powershell 4创建了一个active directory帐户创建脚本 我的老板说有一个新的策略,我们必须为每个用户建立一个登录脚本,有没有办法建立.bat文件并映射我们在脚本中指定的驱动器 我知道有一种方法可以构建.txt文件,但不确定.bat 我需要什么 选择用户需要访问的驱动器 我需要它来构建一个.bat文件,映射先前指定的驱动器。 然后将其移动到DC上的登录脚本文件夹,映射到S,以供将来任何想要这样做的人参考 经过一番周旋后,我自己设法解决了这个问题 $NewName

我已经使用powershell 4创建了一个active directory帐户创建脚本

我的老板说有一个新的策略,我们必须为每个用户建立一个登录脚本,有没有办法建立.bat文件并映射我们在脚本中指定的驱动器

我知道有一种方法可以构建.txt文件,但不确定.bat

我需要什么 选择用户需要访问的驱动器 我需要它来构建一个.bat文件,映射先前指定的驱动器。
然后将其移动到DC上的登录脚本文件夹,映射到S

,以供将来任何想要这样做的人参考

经过一番周旋后,我自己设法解决了这个问题

$NewName = $SAMAccountName
$extension = ".bat"
$FileName = "$SAMAccountName$extension"
$ScriptDrive = "\\IPREMOVED\scripts"

Write-Output "
BAT CONTENTS" `n`n|FT -AutoSize >>LoginScript.txt

Get-ChildItem LoginScript.txt | Rename-Item -NewName $FileName 
Move-Item -Path ".\$FileName" -Destination $ScriptDrive

是什么阻止你继续并尝试这样做?堆栈溢出不是一个脚本编写问题。你可能应该开始用合适的GPO来管理这些东西,而不是无限的登录脚本。。但是如果你真的想这样做,你可以像构建.txt文件一样构建.bat文件。bat文件是基于文本的,它们不需要特殊的魔法编码,我不知道该怎么做。我正在学习powershell@MathiasR.Jessen你有什么好的资源吗?我不知道去哪里look@Paxz我建议使用GPO方法,但是英国NHS内部的信任客户希望在线使用登录脚本。@JamesTimms这太可怕了。TBH,我建议用谷歌搜索LearnPowerShell——关于这个话题有大量的资源和书籍。此外,我建议您向您的经理咨询相关培训——从2012年起,大多数关于Windows Server的Microsoft官方课件都将包含一些关于将PowerShell用于管理目的的指导