Created
October 18, 2019 09:03
-
-
Save tsukanov-as/ca1beee302577929ddef3ed795adc82d to your computer and use it in GitHub Desktop.
Класс-обертка для упрощения работы с 1С через COM
This file contains hidden or 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
class ComObject { | |
[__ComObject] $object | |
ComObject($object) { | |
$this.object = $object | |
} | |
[Object] Get($name) { | |
$res = [__ComObject].InvokeMember($name, 'GetProperty', $null, $this.object, $null) | |
if ($res -is [__ComObject]) { | |
return New-Object ComObject($res) | |
} | |
return $res | |
} | |
Set($name, $value) { | |
[__ComObject].InvokeMember($name, 'SetProperty', $null, $this.object, $value) | |
} | |
[Object] Call($name, $params) { | |
$res = [__ComObject].InvokeMember($name, 'InvokeMethod', $null, $this.object, $params) | |
if ($res -is [__ComObject]) { | |
return New-Object ComObject($res) | |
} | |
return $res | |
} | |
[Object] Call($name) { | |
$res = [__ComObject].InvokeMember($name, 'InvokeMethod', $null, $this.object, $null) | |
if ($res -is [__ComObject]) { | |
return New-Object ComObject($res) | |
} | |
return $res | |
} | |
} | |
# Подключение к 1С | |
$Connector = New-Object -ComObject V83.COMConnector | |
$1c = New-Object ComObject($Connector.Connect("Srvr=localhost;Ref=dev_demo_srv;Usr=Administrator;Pwd=")) | |
$Structure = $1c.Call("NewObject", "Structure") | |
$Structure.Call("Insert", ("Name", "")) | |
$Structure.Call("Count") | |
$Structure.Set("Name", "1C") | |
$Structure.Get("Name") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment