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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michal ZiembaIT AdministratorCommented:
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
Michal ZiembaIT AdministratorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DBThomson76Author Commented:
Looks good
0
Michal ZiembaIT AdministratorCommented:
accepted solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.