Answered by:
VBS + Powershell

Question
-
Hello guys.
I have a little problem here. Right now i have a PS script to set outlook signature for users.
My script gets the employeeID from AD and put it on a weblink.
But i need to have ActiveDirectory Module installed on every computer, and i dont want that.
So i was thinking to use a VBS script to get the employeeID and give it to the PS script.
Is that possible ?
Is it possible to run my PS script and call a VBS to get that result ?
The VBS that gets employeeID is this:
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
contrato = objUser.employeeIDMy PS that gets outlooksignature is this:
## Script criado por Adriano Custodio e Anderson Fantini ##
Import-Module ActiveDirectory
$signame = $env:username
$NTName = (Get-ADUser -Filter {sAMAccountName -eq $signame})
$acesso = "LDAP://" + $NTName.DistinguishedName
$User = [ADSI]$acesso
$contrato = $User.employeeID
$wc = New-Object system.Net.WebClient;
$result = $wc.downloadString("https://portal.zensa.com.br/portalzen/auto_gera_assinatura_script.jsp?contrato="+$contrato+"&auth=CO56UF0JK2YOZQ0JGYSQK8T6H984CE240L4TYR7N")
$userdatapath = $Env:appdata
$folder = $userdatapath + '\\Microsoft\\signatures'
mkdir $folder -force
$Filename = $folder + '\\'+$signame+'.htm'
$SigFull = $result | Out-File $Filename
if (test-path "HKCU:\\Software\\Microsoft\\Office\\14.0\\Common\\General") {
get-item -path HKCU:\\Software\\Microsoft\\Office\\14.0\\Common\\General | new-Itemproperty -name Signatures -value signatures -propertytype string -force
get-item -path HKCU:\\Software\\Microsoft\\Office\\14.0\\Common\\MailSettings | new-Itemproperty -name NewSignature -value $signame -propertytype string -force
get-item -path HKCU:\\Software\\Microsoft\\Office\\14.0\\Common\\MailSettings | new-Itemproperty -name ReplySignature -value $signame -propertytype string -force
}
if (test-path "HKCU:\\Software\\Microsoft\\Office\\15.0\\Common\\General") {
get-item -path HKCU:\\Software\\Microsoft\\Office\\15.0\\Common\\General | new-Itemproperty -name Signatures -value signatures -propertytype string -force
get-item -path HKCU:\\Software\\Microsoft\\Office\\15.0\\Common\\MailSettings | new-Itemproperty -name NewSignature -value $signame -propertytype string -force
get-item -path HKCU:\\Software\\Microsoft\\Office\\15.0\\Common\\MailSettings | new-Itemproperty -name ReplySignature -value $signame -propertytype string -force
}
if (test-path "HKCU:\\Software\\Microsoft\\Office\\16.0\\Common\\General") {
get-item -path HKCU:\\Software\\Microsoft\\Office\\16.0\\Common\\General | new-Itemproperty -name Signatures -value signatures -propertytype string -force
get-item -path HKCU:\\Software\\Microsoft\\Office\\16.0\\Common\\MailSettings | new-Itemproperty -name NewSignature -value $signame -propertytype string -force
get-item -path HKCU:\\Software\\Microsoft\\Office\\16.0\\Common\\MailSettings | new-Itemproperty -name ReplySignature -value $signame -propertytype string -force
}Tuesday, June 27, 2017 12:16 PM
Answers
-
You do not need VBScript. It can be more easily done in PowerShell.
function Get-ADSystemInfo{ <# .LINK https://technet.microsoft.com/en-us/library/ee198776.aspx #> $properties = @( 'UserName', 'ComputerName', 'SiteName', 'DomainShortName', 'DomainDNSName', 'ForestDNSName', 'PDCRoleOwner', 'SchemaRoleOwner', 'IsNativeMode' ) $ads = New-Object -ComObject ADSystemInfo $type = $ads.GetType() $hash = @{} foreach($p in $properties){ $hash.Add($p,$type.InvokeMember($p,'GetProperty', $Null, $ads, $Null)) } [pscustomobject]$hash } Get-ADSystemInfo # get all user groups $userDN = Get-ADSystemInfo | select -expand username [adsi]"LDAP://$userDN" | select -expand EmployeeID
\_(ツ)_/
- Marked as answer by Adriano Lobo Custodio de Oliveira Tuesday, June 27, 2017 12:54 PM
Tuesday, June 27, 2017 12:33 PM -
Ok - its the -expand that is an issue on V2:
This works:
$info = Get-ADSystemInfo $user = [adsi]"LDAP://$($info.UserName)" $user.EmployeeID
\_(ツ)_/
- Marked as answer by Adriano Lobo Custodio de Oliveira Wednesday, June 28, 2017 7:09 PM
Wednesday, June 28, 2017 6:28 PM
All replies
-
You do not need VBScript. It can be more easily done in PowerShell.
function Get-ADSystemInfo{ <# .LINK https://technet.microsoft.com/en-us/library/ee198776.aspx #> $properties = @( 'UserName', 'ComputerName', 'SiteName', 'DomainShortName', 'DomainDNSName', 'ForestDNSName', 'PDCRoleOwner', 'SchemaRoleOwner', 'IsNativeMode' ) $ads = New-Object -ComObject ADSystemInfo $type = $ads.GetType() $hash = @{} foreach($p in $properties){ $hash.Add($p,$type.InvokeMember($p,'GetProperty', $Null, $ads, $Null)) } [pscustomobject]$hash } Get-ADSystemInfo # get all user groups $userDN = Get-ADSystemInfo | select -expand username [adsi]"LDAP://$userDN" | select -expand EmployeeID
\_(ツ)_/
- Marked as answer by Adriano Lobo Custodio de Oliveira Tuesday, June 27, 2017 12:54 PM
Tuesday, June 27, 2017 12:33 PM -
DUDE!!!
thanks a lot, works perfectly.
i just made 1 change...
declared the last line as a variable.
$contrato = [adsi]"LDAP://$userDN" | select -expand EmployeeID
and worked fine.
Thanks a lot man.
Tuesday, June 27, 2017 12:54 PM -
PowerShell has many advantages. I am sure tat VBScript will be removed in the next major release of Windows. Avoid using it.
\_(ツ)_/
Tuesday, June 27, 2017 12:56 PM -
Yep, i dont use VB here, but was the only way i knew to do that.
Thanks a lot man.
Tuesday, June 27, 2017 1:52 PM -
PowerShell has many advantages. I am sure tat VBScript will be removed in the next major release of Windows. Avoid using it.
\_(ツ)_/
I ended up with another problem....
The script does not run on Windows 7 unless i install Powershell3.0
The problem is... HOW to install a .msu file on 300 PC's ?
Cant find that KB on WSUS.
Wednesday, June 28, 2017 5:49 PM -
The script was written for PowerShell 2. It should work. You are likely missing updates to the Net Framework or you have other issues.
\_(ツ)_/
Wednesday, June 28, 2017 6:00 PM -
Well, i dont know, tested on Windows 10 and worked fine...
On windows 7 gets an error saying cant find the username properties
My Wsus is fine and everything is up to date.
Wednesday, June 28, 2017 6:21 PM -
Perhaps you could post the complete error message.
\_(ツ)_/
Wednesday, June 28, 2017 6:24 PM -
Ok - its the -expand that is an issue on V2:
This works:
$info = Get-ADSystemInfo $user = [adsi]"LDAP://$($info.UserName)" $user.EmployeeID
\_(ツ)_/
- Marked as answer by Adriano Lobo Custodio de Oliveira Wednesday, June 28, 2017 7:09 PM
Wednesday, June 28, 2017 6:28 PM -
Dude, you are my Hero!
hahahahaha
worked fine. Thanks, i was already testing a PS script to install .MSU in a GPO, but that is better =D
Thanks again!
Wednesday, June 28, 2017 7:09 PM