bbimis
asked on
convert code to powershell
can someone help me convert this code over to powershell please?
i want to be able to call the function while connected to the computer (i have the connection part done)
i just want to be able to type like 22 and call a function that will produce the results like this bat file.
What i really would like to do is query that registry key for the version numbers and return the result. I'm not sure how to query the registry in powershell.
Thanks!
@echo off
setlocal enabledelayedexpansion
for /f "tokens=3 delims=." %%a in ('reg query "HKEY_CLASSES_ROOT\Word.Application\CurVer"') do set reg=%%a
set /a i=0
for %%b in (9 11 12 14 15) do (
if %%b == %reg% goto setver
set /a i+=1
)
:setver
set /a n=0
for %%c in (2000 2003 2007 2010 2013) do (
if !n! == !i! set ver=%%c && goto endloop
set /a n+=1
)
:endloop
echo Microsoft Office gVersion: %ver%
echo.
endlocal
:end
pause
i want to be able to call the function while connected to the computer (i have the connection part done)
i just want to be able to type like 22 and call a function that will produce the results like this bat file.
What i really would like to do is query that registry key for the version numbers and return the result. I'm not sure how to query the registry in powershell.
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$remotecomputer = "<remotecomputername>"
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('ClassesRoot', $remotecomputer)
$RegKey = $Reg.OpenSubKey("Word.Application\\CurVer")
$ver = $RegKey.GetValue($null)
$ver
$ver = $ver.Split(".")
$v = switch ($ver[2])
{
"9" {"2000"}
"11" {"2003"}
"12" {"2007"}
"14" {"2010"}
"15" {"2013"}
}
Write-Output "Microsoft Office Version: $v"
ASKER
if it requires authentication do i use the -credentials -creds in this as well?
sorry new at powershell
sorry new at powershell
I would just launch powershell as whatever user has permissions (i also think you need remote registry turned on). You can do this by shift-right clicking the powershell shortcut and running as different user.
just realized i have that extra $ver in there on its own line, was using it for diagnostics, but you can remove it.
ASKER
well i can't get it to work remotely. I guess i will just use the bat file :(
i'm having issues passing it the creds
i tried your method above but it will not work for me.
i need to be able to somehow pass the $creds = get-credential
then -Computername $compname -Credientals $creds
but i can't figure out how to use it with the openremotebasekey
thanks!
i'm having issues passing it the creds
i tried your method above but it will not work for me.
i need to be able to somehow pass the $creds = get-credential
then -Computername $compname -Credientals $creds
but i can't figure out how to use it with the openremotebasekey
thanks!
you opened powershell as something like a domain admin and ran and it didn't work? what error are you getting?
ASKER
I suppose the only way it can be done is via wmi instead of .net remote registry. I will see if I can make something really quick in about an hour.
ASKER
thanks for your time. i enjoy learning this but i'm clueless :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
one question where can i look to understand what the reference 2147483648 is for?
not sure why you are storing that value? is it a default that must be used? Just trying to understand thanks!
not sure why you are storing that value? is it a default that must be used? Just trying to understand thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks got it !
sweet, have a good one.
ASKER
i need to pass that to a remote system so i can query the registry on the remote. sorry and thanks!