Want to covert in to powershell
-
26 октября 2010 г. 13:00
I have some part of my batch script & I want to convert it into powershell
Batch Script
:DTVerCheck
ver | %WINDIR%\SYSTEM32\find "Windows XP" >nul
If not %errorlevel%==1 goto XPCheck
Ver | %WINDIR%\SYSTEM32\find "Windows [Version 6" >nul
if not %errorlevel%==1 goto VistaCheck
ver | %WINDIR%\SYSTEM32\find "Windows [Version 5.2" >nul
if not %errorlevel%==1 goto XPCheck
ver | %WINDIR%\SYSTEM32\find "Windows [Version 5.0" >nul
if not %errorlevel%==1 goto NTServercall %LOGONSERVER%\NETLOGON\gettype.exe
if errorlevel=9 goto FILENOTFOUND
if ERRORLEVEL=8 goto NTServer
if ERRORLEVEL=7 goto NTServer
if ERRORLEVEL=6 goto NTServer
if ERRORLEVEL=5 goto NTServer
if ERRORLEVEL=4 goto NTServer
if ERRORLEVEL=3 goto NTServer
if ERRORLEVEL=2 goto XPCheck
if ERRORLEVEL=1 goto XPCheckIn the above Code DTVerCheck, FILENOTFOUND,NTServer,XPCheck are all functions. Also how call we replace call in powershell. I tried little bit but not sure whether it's write or not. Below is the code that I have tried
Function DTVerCheck
if ((get-wmiobject Win32_OperatingSystem).Caption -like "*windows xp*")
{XPCheck}
if ((get-wmiobject Win32_OperatingSystem).Caption -like "*Windows [Version 6*")
{VistaCheck}
if ((get-wmiobject Win32_OperatingSystem).Caption -like "*Windows [Version 5.2*")
{XPCheck}
if ((get-wmiobject Win32_OperatingSystem).Caption -like "*Windows [Version 5.0*")
{NTServer}but I have no idea how to script after the call statement.
Все ответы
-
26 октября 2010 г. 13:19Модератор
One way is to use script blocks:
$XPCheck = {
<XP Check routines go here>
}
if ((get-wmiobject Win32_OperatingSystem).Caption -like "*windows xp*")
{&$XPCheck}
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "- Помечено в качестве ответа IamMredMicrosoft Employee, Owner 27 октября 2010 г. 12:20
-
26 октября 2010 г. 13:27
But even mine will work right ? My main concern is how I will script for
call %LOGONSERVER%\NETLOGON\gettype.exe
if errorlevel=9 goto FILENOTFOUND
if ERRORLEVEL=8 goto NTServer
if ERRORLEVEL=7 goto NTServer
if ERRORLEVEL=6 goto NTServer
if ERRORLEVEL=5 goto NTServer
if ERRORLEVEL=4 goto NTServer
if ERRORLEVEL=3 goto NTServer
if ERRORLEVEL=2 goto XPCheck
if ERRORLEVEL=1 goto XPCheckhow I will use call in powershell.
-
26 октября 2010 г. 14:47Модератор
Hi,
You don't need to use the gettype.exe in PowerShell since it can use WMI. For example:
$osName = (get-wmiobject Win32_OperatingSystem).Caption
if ($osName -like "*windows xp*) {
...
}However: A PowerShell script may not be the best choice to use for a logon script unless you have a guarantee somehow that every computer connected to your network has PowerShell installed on it.
Bill
- Помечено в качестве ответа IamMredMicrosoft Employee, Owner 27 октября 2010 г. 12:20
-
26 октября 2010 г. 15:18
I can take care of having powershell on each machine, but the reason I am trying this is Win 7 & the later versions of Win will not support .bat fully. Hence i have planned to use powershell.
Also If I ignore the half part of my batch code that is after gettype.exe it will work fine right ? and the OS will be determined.
-
26 октября 2010 г. 15:24Модератор
What does "the later versions of Win will not support .bat fully" mean? Windows 7 has Cmd.exe, which executes shell scripts ("batch files") just fine.
Bill
-
26 октября 2010 г. 15:31Ok shall I continue using batch file.
-
26 октября 2010 г. 15:59Модератор
For logon scripts, I recommend WSH scripts. But it depends on what specifically you want to do. If what you have is working, why change it?
Bill

