I ve checked quite a few other questions here but was unable to find what I need. I am currently trying to automate the process of finding out what VMs are in what Hyper V servers. Here is my current script.
@echo off
set /P dc= "Which DC do you want? "
dsquery computer -name %DC%VUT* > dsquery.txt
type dsquery.txt | findstr /v IMAGINGOU | findstr /v OTHEROU > dsquery2.txt
powershell -command Get-Content dsquery2.txt | ForEach-Object { $_ -replace "CN= , "" } | Set-Content dsquery3.txt
powershell -command Get-Content dsquery3.txt | ForEach-Object { $_ -replace ,OU=CAM,OU=Exchange,OU=Server,DC=RED001,DC=local" , "" } | Set-Content serverlist.txt
powershell -command .Get-HyperVMod.ps1 -file output.csv
The problem I have hit is the servers that I can do dsquery from (Win2k3) can t do the ForEach-Object because they have an older version of Powershell and the Win2k8 servers that can do the ForEach-Object can t do a dsquery.
这里是我试图除服务器名称外复制和删除所有频率产出的样本。
"CN=SERVER001,OU=VUT,OU=Infastructure,OU=Server,DC=dcname,DC=local"
"CN=SERVER008,OU=ImagingWDS,DC=red002,DC=local"
Output should be
SERVER001
SERVER008
任何建议,要么采用另一种方法,要么只是我从档案中删除额外案文的小问题。