windows – 创建要禁用的计算机列表
发布时间:2020-12-13 22:47:29 所属栏目:Windows 来源:网络整理
导读:我的任务是自动禁用/删除旧计算机.不幸的是,我发现我为此任务提供的数据有很多错误并且我在验证它时遇到了问题.这里的要求是计算机帐户必须存在,它不能是重复的,它不能是服务器操作系统,并且计算机的帐户密码在过去10天内不得重置.我已经能够单独验证所有这
我的任务是自动禁用/删除旧计算机.不幸的是,我发现我为此任务提供的数据有很多错误并且我在验证它时遇到了问题.这里的要求是计算机帐户必须存在,它不能是重复的,它不能是服务器操作系统,并且计算机的帐户密码在过去10天内不得重置.我已经能够单独验证所有这些,但当我尝试将验证合并到一个脚本中时,我失败了.具体来说,我无法通过重复数据步骤.
这是代码: $file = "D:TranscriptsADPCverify" + (get-date -Format yyyymmdd-hhmmss) + ".txt" start-transcript -LiteralPath $file $date = Get-Date $computers = Get-Content D:ContentADPCverifyunverified.txt | sort-object -unique $list = Get-Content D:ContentADPCDisablecomputers.txt $name = 'null' ForEach($computer in $computers){ $prevname = $name $name = (Get-ADComputer -Identity $computer -Server server).name $PCObject = Get-ADComputer -Identity $computer -Server server -Properties * $OS = $PCObject.OperatingSystem $pwdLastSet = [DateTime]::FromFiletime([Int64]::Parse($PCobject.pwdLastSet)) $TimeSince = New-TimeSpan $pwdLastSet $date if($name -eq $prevname){ Add-Content D:ContentADPCDisableFailedComputers.txt $computer write-host "Machine " + $computer + " does not exist and has been added to the failed computers list." }elseif($OS -contains 'Windows Server'){ Add-Content D:ContentADPCDisableFailedComputers.txt $computer write-host "Machine " + $computer + " has a server OS and will be added to the failed computer list." }elseif($TimeSince.totaldays -lt 10){ Add-Content D:ContentADPCDisableFailedComputers.txt $computer write-host "Machine " + $computer + "'s password was reset " + $TimeSince.totaldays + " days ago and has been added to the failed computer list." }else{ Add-Content D:ContentADPCDisableComputers.txt $name write-host "Machine " + $name + " has been succesfully added to the computers to disable list." } } Stop-Transcript 该脚本似乎无法通过第二个if语句.如果我需要提供更多信息或者我错过了一个括号,请告诉我. $file = "D:TranscriptsADPCverify" + (get-date -Format yyyymmdd-hhmmss) + ".txt" start-transcript -LiteralPath $file $date = Get-Date $computers = Get-Content D:ContentADPCverifyunverified.txt | sort-object -unique $list = Get-Content D:ContentADPCDisablecomputers.txt $name = 'null' $server = '' ForEach($computer in $computers){ Try{ $PCObject = Get-ADComputer -Identity $computer -Server $server -Properties * $name = $PCObject.Name $OS = $PCObject.OperatingSystem $pwdLastSet = [DateTime]::FromFiletime([Int64]::Parse($PCobject.pwdLastSet)) $TimeSince = New-TimeSpan $pwdLastSet $date if($OS.StartsWith('Windows Server')){ Add-Content D:ContentADPCDisableFailedComputers.txt $computer write-host "Machine " $computer " has a server OS and will be added to the failed computer list." }elseif($TimeSince.TotalDays -lt 10){ Add-Content D:ContentADPCDisableFailedComputers.txt $computer write-host "Machine " $computer "'s password was reset " + $TimeSince.TotalDays + " days ago and has been added to the failed computer list." }else{ Add-Content D:ContentADPCDisableComputers.txt $name write-host "Machine " $name " has been succesfully added to the computers to disable list." } } Catch{ Add-Content D:ContentADPCDisableFailedComputers.txt $computer write-host "Machine " $computer " does not exist and has been added to the failed computers list." } } Stop-Transcript 这是最终结果.我使用try / catch选项来抑制错误.我的问题是与-contains比较.感谢您的帮助! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 如何在node.js上杀死一个打开的进程?
- 拒绝服务 – 阻止IP地址,防止DoS攻击
- Windows – 如何将所有查询记录到Outlook Web Access(msexc
- xaml – 如何在Windows Phone 8.1通用应用程序中使用Window
- Windows服务控制台应用用户
- Windows – 在命令行验证域凭据
- Windows – sox FAIL util:无法加载MAD解码器库(libmad)函
- .net-3.5 – 在没有DVD的Windows Server 2012上安装Net 3.5
- 我们可以通过Windows中的命令提示符运行mysql查询吗?
- 在Windows上正常终止命令行应用程序
推荐文章
站长推荐
- 忽略Windows Azure虚拟应用程序中的文件
- 如何在Windows中检查文件的创建者?
- windows-8 – 如何在Windows应用商店应用中实现耗
- wpf – 如何实现类似于Windows Vista文件资源管理
- 如何为自己的npm注册表配置save-prefix
- windows-server-2008 – 经过MS Windows Server
- windows-server-2012 – 如何正确地为文件服务器
- windows-7 – 如何获取目录连接的实际文件夹路径
- windows-server-2008 – 如何知道Windows防火墙上
- windows-server-2012 – 事件查看器警告:“从AC
热点阅读