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
Solved

Need to convert a simple VB script to PowerShell

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 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