Cybersecurity
DevOps Cloud
IT Operations Cloud
OpenText product name changes coming to the community soon! Learn more.
Recently I’ve been working with a customer that has planned to change their User Source to a new domain. Obviously they were wondering what user assignments they had in their existing environment so they can make the same assignments to objects in the new User Source.
If you search the community archives you might find an old batch file from our old legend Shaun Pond that uses zman to query the ZENworks environment and I thought it would be useful to get a new post out with a bash script that does the same, in addition I’ve added a quick check to see if there are any schedules assigned.
The script is a nice example that shows how zman can be used, in this case to get a list that the customer can work with to modify their assignments. Unfortunately zman isn’t able to get the assignment details, but in the case of the customer I’ve been working with that wasn’t an issue as all ZENworks applications are published in the ZENworks Application Launcher window. Application schedules will need to be looked at individually to see how they need to be migrated.
Comments on how the script works are added to the script. At the end you will finds a CSV file in /tmp with all user assignments.
#!/bin/bash
#
# Export a list of Bundle Relationships in ZENworks
#
# First the ZENworks Administrator credentials need to be stored
read -p "Please enter the name of the ZENworks Administrator: " name
zman asc $name
# The script will start zman as a service, this will increase the performance
# This step will also verify if the ZENworks Administrator credentials are stored properly, if not the script will end
zman ssas | grep -q 'zman service requires admin credentials to be stored.' && echo "Credentials are not stored properly, exit script" && exit
# Cleanup files if they already exist from a previouse run
if [ -e /tmp/BundleList.txt ]; then
rm /tmp/BundleList.txt
fi
if [ -e /tmp/BundleAssignment.csv ]; then
rm /tmp/BundleAssignment.csv
fi
# Create a file with all bundles that need to be processed
echo "Build BundleList file"
zman bl -r --terse | grep -E "Windows Bundle|Directive Bundle|File Bundle" >> /tmp/BundleList.txt
# Parse through the bundle file and find if any User Assignments exist
while IFS= read -r line; do
path=$(echo $line | cut -d '|' -f 4)
blname=$(echo $line | cut -d '|' -f 1)
fullpath="$path/$blname"
echo "Processing $fullpath"
if ! zman blas "$fullpath" -t user --terse | grep -q "No results found"; then
Assignments=$(zman blas "$fullpath" -t user --terse |tail -n +4 |head -n -3)
while read Assignmentline ; do
AssignedObject="$(cut -d'|' -f4 <<<"$Assignmentline")"
AssignedObject+="/"
AssignedObject+="$(cut -d'|' -f1 <<<"$Assignmentline")"
AssignedSchedule=$(zman bvas user "$fullpath" "$AssignedObject")
if [[ "$AssignedSchedule" == *"No schedule found."* ]]; then
HasSchedule="No Schedule"
else
HasSchedule="Bundle has a Schedule configured"
fi
AssignmentDetails="$fullpath"",""$AssignedObject"",""$HasSchedule"
echo $AssignmentDetails >> /tmp/BundleAssignment.csv
done <<< "$Assignments"
fi
done < /tmp/BundleList.txt
One additional Note: The script will launch zman as a service, this speeds up the process. For this to work you will need to run the script with the root user. If you are using the zenadmin user you will have to comment out the zman ssas and zman sss commands in the script and be patient while the script will run.