Powershell script to replace IFMEMBER

I am cuurently using a logon cmd script to check and do something and write to a file the first time.

Can someone help me to convert this from a command script to a Powershell script?

example:

:ADOBEREADER
REM This Accepts the use aggreement
IFMEMBER "AdobeReader"
IF %ERRORLEVEL%==0 GOTO NEXTSTEP
ECHO IN AdobeReader!
IF EXIST "%homeshare%\2K12AdobeReader.LOG" GOTO NEXTSTEP
REGEDIT /I /S C:\Scripts\Regfiles\AdobeReader.Reg
ECHO Adobe Reader settings imported on %TODAY% at %NOW% >"%homeshare%\XEN2K12AdobeReader.LOG"

:NEXTSTEP

Thanks!
DBThomson76Asked:
Who is Participating?
 
Michal ZiembaIT System ArchitectCommented:
OK. So the final script should look like this.

$HomeShare = $env:HOMESHARE
$group = "AdobeReader"
$memberOf = ([ADSISEARCHER]"samaccountname=$($env:USERNAME)").Findone().Properties.memberof -replace '^CN=([^,]+).+$','$1'
if($memberOf -contains $group)
{
  write-host "IN AdobeReader!" 
  if (Test-Path  ("$HomeShare\2K12AdobeReader.LOG")){
    Reg import "C:\Scripts\Regfiles\AdobeReader.Reg"
    "Adobe Reader settings imported on  $(get-date)"|Out-File "$HomeShare\XEN2K12AdobeReader.LOG"
    }
}

Open in new window

0
 
Michal ZiembaIT System ArchitectCommented:
Give it a try...
$group = "AdobeReader"
$memberOf = ([ADSISEARCHER]"samaccountname=$($env:USERNAME)").Findone().Properties.memberof -replace '^CN=([^,]+).+$','$1'
if($memberOf -contains $group)
{
  write-host "IN AdobeReader!" 
  if (Test-Path  ("%homeshare%\2K12AdobeReader.LOG")){
    Reg import "C:\Scripts\Regfiles\AdobeReader.Reg"
    "Adobe Reader settings imported on  $(get-date)"|Out-File "%homeshare%\XEN2K12AdobeReader.LOG"
    }
}

Open in new window

0
 
DBThomson76Author Commented:
Michal,

Your script almost worked. It did not convert the %homeshare% which caused it to fail.
I needed to add $HomeShare = $env:HOMESHARE to the script for it to convert properly and then I changed the %homeshare% to be $HomeShare and then it worked.

Thanks!
0
 
DBThomson76Author Commented:
Looks good
0
 
Michal ZiembaIT System ArchitectCommented:
accepted solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.