Solved

Need to convert a simple VB script to PowerShell

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

760 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

26 Experts available now in Live!

Get 1:1 Help Now