Solved

Need to convert a simple VB script to PowerShell

Posted on 2016-09-16
3
103 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

717 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