Link to home
Start Free TrialLog in
Avatar of DBThomson76
DBThomson76Flag for United States of America

asked on

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!
Avatar of Michal Ziemba
Michal Ziemba
Flag of Poland image

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

Avatar of DBThomson76

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of Michal Ziemba
Michal Ziemba
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looks good
accepted solution