Last active
September 22, 2020 18:46
-
-
Save yomon8/5995038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[parameter(Mandatory=$true,HelpMessage="登録するSAPユーザIDを入力してください")] | |
[String]$newSAPUserID, | |
[parameter(Mandatory=$true,HelpMessage="登録するSAPユーザの初期パスワードを入力してください")] | |
[String]$initialSAPUserPassword, | |
[parameter(Mandatory=$true,HelpMessage="登録するSAPユーザの姓を入力してください")] | |
[String]$lastName, | |
[parameter(Mandatory=$true,HelpMessage="登録するSAPユーザの名を入力してください")] | |
[String]$firstName, | |
[parameter(Mandatory=$false,HelpMessage="ユーザタイプ(A:ダイアログ、B:システム、C:通信、S:サービス、L:サービス)")] | |
[String]$userType | |
) | |
if($userType -eq $null) | |
{ | |
$userType = "A" #Dialog User | |
} | |
$scriptPath = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) | |
[void][Reflection.Assembly]::LoadFile("$scriptPath\sapnco.dll") | |
[void][Reflection.Assembly]::LoadFile("$scriptPath\sapnco_utils.dll") | |
$lofoninfo = [xml](Get-Content "$scriptPath\saplogoninfo.xml") | |
#Set SAP logon infomation | |
$rfc = New-Object SAP.Middleware.Connector.RfcConfigParameters | |
$rfc.Add("NAME",$lofoninfo.LogonInfo.SAPSID) | |
$rfc.Add("SYSID",$lofoninfo.LogonInfo.SAPSID) | |
$rfc.Add("ASHOST",$lofoninfo.LogonInfo.SAPHOST) | |
$rfc.Add("SYSNR",$lofoninfo.LogonInfo.SAPSYSNUM) | |
$rfc.Add("CLIENT",$lofoninfo.LogonInfo.SAPCLIENT) | |
$rfc.Add("USER",$lofoninfo.LogonInfo.SAPUSER) | |
$rfc.Add("PASSWD",$lofoninfo.LogonInfo.SAPPASSWORD) | |
#Set SAP Function | |
$rfcDest = [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($rfc) | |
$sapFunc = $rfcDest.Repository.CreateFunction("BAPI_USER_CREATE1") | |
$sapFunc.SetValue("USERNAME",$newSAPUserID) | |
$structLogonData = $sapFunc.GetStructure("LOGONDATA") | |
$structLogonData.SetValue("USTYP",$userType) | |
$structInitPasswd = $sapFunc.GetStructure("PASSWORD") | |
$structInitPasswd.SetValue("BAPIPWD",$initialSAPUserPassword) | |
$structAddress = $sapFunc.GetStructure("ADDRESS") | |
$structAddress.SetValue("LASTNAME",$lastName) | |
$structAddress.SetValue("FIRSTNAME",$firstName) | |
#Execute SAP Function | |
$sapFunc.Invoke($rfcDest) | |
#Display SAP Function Return Message | |
$return = $sapFunc.GetTable("RETURN") | |
$return.GetString("MESSAGE") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment