Differences
This shows you the differences between two versions of the page.
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 | ||
- | < | + | < |
# | # | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
Line 56: | Line 56: | ||
====== Powershell ====== | ====== Powershell ====== | ||
+ | <note important> | ||
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: | ||
+ | * 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 | ||
- | < | + | < |
# 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 ' | Add-PSSnapin -Name ' | ||
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 = " | $identificator = " | ||
$obj | $obj | ||
Line 91: | Line 97: | ||
| | ||
# prepare list | # prepare list | ||
+ | | ||
$resultList = @() | $resultList = @() | ||
- | # Iterate thru response object | + | # Iterate thru response object |
foreach ($item in $obj) { | foreach ($item in $obj) { | ||
| | ||
Line 99: | Line 106: | ||
$resultMap = @{ } | $resultMap = @{ } | ||
| | ||
- | # iterate thru each result | + | # iterate thru each result |
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]:: | if (![string]:: | ||
Line 107: | Line 115: | ||
| | ||
$resultMap.add(" | $resultMap.add(" | ||
+ | | ||
# 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 " | if ($name -eq " |