?
Solved

Need to convert a simple VB script to PowerShell

Posted on 2016-09-16
3
Medium Priority
?
113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

765 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