Solved

Need to convert a simple VB script to PowerShell

Posted on 2016-09-16
3
65 Views
Last Modified: 2016-09-28
Hello, in order to move with the times I have a VB script that I would like to convert to PowerShell script to be used with Windows 10 clients.

Could you convert this for me?

Thanks.

' **********************************************************************
' *** Office User Info Populator
' **********************************************************************


On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
Set objWord = CreateObject("Word.Application")
Objword.UserName = objuser.displayname
objWord.UserInitials = Ucase(Left(objUser.givenName, 1)) & Ucase(Left(objUser.SN, 1))
objWord.Quit

Open in new window

0
Comment
Question by:meirionwyllt
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41801758
This should do the trick:
# **********************************************************************
# *** Office User Info Populator
# **********************************************************************

$ADUser = ([AdsiSearcher]"(&(objectCategory=person)(objectClass=User)(samAccountName=$($ENV:UserName)))").FindAll()
$Word = New-Object -ComObject "Word.Application"
$Word.UserName = $ADUser.Properties.displayname
$Word.UserInitials = "$($ADUser.Properties.givenname.ToUpper()[0])$($ADUser.Properties.sn.ToUpper()[0])"
$Word.Quit()
[void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($Word)

Open in new window

0
 

Author Comment

by:meirionwyllt
ID: 41801770
Hi, thanks for that.  I'll test and report back...
0
 

Author Comment

by:meirionwyllt
ID: 41819883
Thanks a lot - that works.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
A brief introduction to what I consider to be the best editor for PowerShell.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now