Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devel:documentation:systems:dev:how_to_write_scripts_for_winrm_ad_connector [2019/09/05 11:46]
kucerar ps example
devel:documentation:systems:dev:how_to_write_scripts_for_winrm_ad_connector [2021/11/29 13:39] (current)
kucerar Write output
Line 9: Line 9:
  
 This is example create script This is example create script
-<code>+<code python>
 #!/usr/bin/env python #!/usr/bin/env python
 # -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
Line 56: Line 56:
  
 ====== Powershell ====== ====== Powershell ======
 +<note important>When connector server is on Windows use Write-Output instead of Write-Host</note>
 I'll use same solution as with Python script and jump directly to some example script I'll use same solution as with Python script and jump directly to some example script
 +
 +Tips:
 +  * Use -Confirm:$false parameter to avoid "freezing" of your script
 +  * Use -ErrorAction Stop or -ea Stop for better error handeling, because some command will print error to stdout by default so you won't be able to catch them without this parameter
  
 This is example search script so I can show handling of response This is example search script so I can show handling of response
-<code>+<code powershell>
 # Search script, which will return information about user's exchange account # Search script, which will return information about user's exchange account
 # INPUT: # INPUT:
Line 66: Line 70:
  
 Write-Host "PS Search started" Write-Host "PS Search started"
 +
 #Needed to load Exchange cmdlets #Needed to load Exchange cmdlets
 Add-PSSnapin -Name '*Exchange*' Add-PSSnapin -Name '*Exchange*'
Line 74: Line 79:
 try { try {
     #$uid will be replace with some value from python, in case that search is for all (reconcilation) we will have empty string here that's the reason why we are assigning the value to new variable     #$uid will be replace with some value from python, in case that search is for all (reconcilation) we will have empty string here that's the reason why we are assigning the value to new variable
 +    
     $identificator = "$uid"     $identificator = "$uid"
     $obj     $obj
Line 91: Line 97:
          
     # prepare list     # prepare list
 +    
     $resultList = @()     $resultList = @()
  
-    # Iterate thru response object+    # Iterate thru response object e.g. We get 10 users so we need to create map for each of them inside this loop and add it to list
     foreach ($item in $obj) {     foreach ($item in $obj) {
                  
Line 99: Line 106:
         $resultMap = @{ }         $resultMap = @{ }
                  
-        # iterate thru each result e.g. We get 10 users so we need to create map for each of them+        # iterate thru each result attributes
         foreach ($attr in $item.psobject.Properties) {         foreach ($attr in $item.psobject.Properties) {
 +            
             # care only about attributes which has some value             # care only about attributes which has some value
             if (![string]::IsNullOrWhitespace($attr.Value)) {             if (![string]::IsNullOrWhitespace($attr.Value)) {
Line 107: Line 115:
                          
                 $resultMap.add("$name", "$value")                 $resultMap.add("$name", "$value")
 +                  
                 # now we need to fill __UID__ and __NAME__ attribute as connid needs this values                 # now we need to fill __UID__ and __NAME__ attribute as connid needs this values
                 if ($name -eq "SamAccountName") {                 if ($name -eq "SamAccountName") {
  • by kucerar