working-update-script

This commit is contained in:
Justin Donnelly
2020-06-25 14:56:26 -04:00
parent 82cf1b2878
commit 15e2e5ac49
4 changed files with 158 additions and 100 deletions

View File

@@ -1,31 +1,62 @@
# customobj.ps1
#### Read that sheet yo
$filePath = "testdata.xlsx"
#
# Rando Vars
$
# $InputHash = @(Import-Excel testdata.xlsx)
$OutputHash = @{}
# Import-Excel $filePath |
# ForEach-Object {
# # $OutputHash[$_.Directory] = $_.Directory #| Write-Host
# # $OutputHash[$_.UserName] = $_.UserName #| Write-Host
# # $OutputHash[$_.UserName] = $_.UserName #| Write-Host
# $OutputHash.Add($_.Server,$_.UserName,$_.UserRole,$_.StreamAdminNN,$_.StreamPublishAccess,$_.StreamReadAccess)
# # Write-Host ($_.Directory)"\"($_.UserName)#": "($_.UserRole)
# # Write-Host ($_.Directory)"\"($_.UserName)#": "($_.UserRole)
# }
Get-ChildItem -Path cert:\CurrentUser\My | Where-Object {$_.subject -eq 'CN=QlikClient'} | Connect-Qlik -computername https://qseow.browntown.local:4242 -Username browntown\djx | Out-Null
$idList = @(
'djx'
'qlik'
# 'qlik'
)
$UserCustProp = foreach ($ID in $idList) {
# Use "Get-QlikUser to filter on userId key, then pipe through Where-Object to filter results on userDirectory
if ($qlikUser = Get-QlikUser -filter "userId eq '$ID'" | Where-Object {$_.userDirectory -eq 'BROWNTOWN'} ) {
if ($customProperties = Get-QlikUser -id $qlikUser.id) {
[PSCustomObject]@{
UserID = $ID
CustomProp = ForEach-Object($customProperties.value){}
# stream = if ($name in $customProperties.customProperties.definition.name) {
# $propList = $propList + $($customProperties.customProperties.value)
# }
# Write-Host $ID+" "$propName+" "$propList
}
# $propName+$propList
}
# For each filtered result, use the resulting ID# to do a "full" lookup on the user, retrieve customProps
if ($idHash = Get-QlikUser -id $qlikUser.id) {
# ################# CustomObject Block
# [PSCustomObject]@{
# "UserID" = $ID
# "UserAccessLevel" = ( $idHash.customProperties.definition.name )
# # "UserAccessLevel" = ( $propHash.value | Get-Unique)
# # "Stream ==> Access" = $idHash.customProperties.definition.name+" "+$idHash.customProperties.value
# "CustProp" = $idHash.customProperties.value
# }
# ################# CustomObject Block END
}
}
}
$StreamPerms = foreach ($StreamName in ($customProperties.customProperties | Select-Object -Unique)) {
[PSCustomObject]@{
StreamName = $StreamName.definition.name
MemberList = ($customProperties | Where-Object customProperties -Contains $StreamName).value
}
}
# $StreamPerms = foreach ($StreamName in ($idHash.customProperties.value)) {
# [PSCustomObject]@{
# StreamName = $StreamName
# # MemberList = ($idHash | Where-Object customProperties -Contains $StreamName).value
# MemberList = ($idHash | Where-Object customProperties -Contains $StreamName).value
# }
# }
$UserCustProp #| Format-Table -a
$StreamPerms #| Format-Table -a
$UserCustProp | Format-List
# Write-Host "'Value of $idHash' = ${customPropHash}"
# $StreamPerms | Format-Table -a

View File

@@ -1,71 +1,44 @@
# Requires -Modules Qlik-Cli, Import-Excel
##### Read in XLSX
# Set Vars / Create hash?
# foreach line in the file, create a unique entry
##### Read in Users from QSEoW
# read in each user from QSEoW and look for duplicate entries
# (domain.userid.role.streamnn,streampub,streamread)
##### Check for dupes/conflicts
# If conflict on domain.userid.role.X != then dump both entries to log or xlsx tab and move on.
##### Write each unique domain.userid command to stdout
# Is there a way to make this too long?
#Requires -Modules Qlik-Cli,ImportExcel
$filePath = "testdata.xlsx"
Write-Output $filePath
# $InputHash = @(Import-Excel testdata.xlsx)
$OutputHash = @{}
# $OutputHash = @{}
Import-Excel $filePath |
ForEach-Object {
$OutputHash[$_.Directory] = $_.Directory #| Write-Host
$OutputHash[$_.UserName] = $_.UserName #| Write-Host
# Foreach line, add UserName,StreamAdminNN,StreamPublishAccess,StreamReadAccess
$xlsx = Import-Excel $filePath
foreach ($row in $xlsx) {
if ($row.StreamAdminNN) {
$OutputHash = $OutputHash += $row.StreamAdminNN
}
if ($row.StreamPublishAccess) {
$OutputHash = $OutputHash += $row.StreamPublishAccess
}
if ($row.StreamReadAccess) {
$OutputHash = $OutputHash += $row.StreamReadAccess
}
#
# $line = $row.UserName + "=" + $row.StreamAdminNN + $row.StreamPublishAccess + $row.StreamReadAccess
#
$line = '"' + $line + '";'
$line = $line += $OutputHash
$strNewLine += $line
}
# $OutputHash[$_.FullUserName] = $_.Directory + '\' + $_.UserName | Write-Host
Write-Host ($_.Directory)"\"($_.UserName)
}
# Write-Host ($_.Directory)"\"($_.UserName)
# $OutputHash.Count
# $user, $userAccessLevel, @streamAdminNN, @streamPublishAccess, @streamReadAccess
# ForEach-Object ($line in $InputFile) {
# if ( $_.UserRole = "StreamAdmin" ) {
# # $OutputHash.StreamAdminNN = $_.Streams
# $OutputHash.Add("StreamAdminNN",$_.Streams)
# $OutputHash.Add("StreamPublishAccess",$_.Streams)
# $OutputHash.Add("StreamReadAccess",$_.Streams)
# $OutputHash.Add("UserAccessLevel",$_.UserRole)
# Write-Host $OutputHash
# # = $_.ID1.ToString( "00000000" )
# } elseif ( $_.UserRole = "Consumer" ) {
# # $OutputHash.Add("StreamAdminNN",$_.Streams)
# # $OutputHash.Add("StreamPublishAccess",$_.Streams)
# $OutputHash.Add("StreamReadAccess",$_.Streams)
# $OutputHash.Add("UserAccessLevel",$_.UserRole)
# Write-Host $OutputHash
# } elseif ( $_.UserRole = "AppDeveloper") {
# # $OutputHash.Add("StreamAdminNN",$_.Streams)
# $OutputHash.Add("StreamPublishAccess",$_.Streams)
# $OutputHash.Add("StreamReadAccess",$_.Streams)
# Write-Host $OutputHash
# } else {
# $OutputHash.Add("UserAccessLevel",$_.UserRole)
# } # End IF
# # Write-Host $OutputHash #### Dump hashtable to stdout/console
# } #EndForEach
#### OutputLine
# Update-QlikUser -customProperties StreamAdminNN=value1,value2,value3,value4,value5,etc.
##### Read in existing User from Qlik-Connect
# Create entry in hash, compare keys from two tables?
# If there is a diff, don't update, just log both entries would look like
#
# Each Directory.UserName can only exist once, make sure not to overwrite because of bad handling of PK
# Update-QlikUser -customProperties Admin=True,Sales=True,Marketing=True,Developer=True
# Update-QlikUser -customProperties StreamAdminNN=
$strNewLine
# $OutputHash
# Write-Host
# Write-Host "=================================="
# Write-Host

View File

@@ -1,21 +1,49 @@
#Requires -Modules Qlik-Cli
# Connect-Qlik | Out-Null
#Requires -Modules Qlik-Cli,ImportExcel
# Use Cert Store (on Windows) to search for the "QlikClient" certificate. We'll need to handle this differently if connecting to multiple engines
# Should not need the -Username flag if certs are working (need to revalidate this with 2 clients)
Get-ChildItem -Path cert:\CurrentUser\My | Where-Object {$_.subject -eq 'CN=QlikClient'} | Connect-Qlik -computername https://qseow.browntown.local:4242 -Username browntown\djx
# Get-QlikUser -filter "userid eq 'djx'" -full | Update-QlikUser -customProperties Admin=True,Sales=True,Marketing=True,Developer=True
# Get-QlikUser -filter "userId eq '$ID'" | Where-Object {$_.userDirectory -eq 'BROWNTOWN'} )
####
# Find current list of CPs for each user in the BROWNTOWN directory, where the CustProp "ChakaKhana" is not defined.
$currentCPlist = $(Get-QlikUser -filter "userDirectory eq 'BROWNTOWN'" -full).customProperties | Where-Object { $_.definition.name -ne "ChakaKhan" }
# Loop through the list of CPs captured for the user filter.
foreach ($currentCPval in $currentCPlist) {
$idList = @(
'djx'
'qlik'
)
Get-ChildItem -Path cert:\CurrentUser\My | Where-Object {$_.subject -eq 'CN=QlikClient'} | Connect-Qlik -computername https://qseow.browntown.local:4242 -Username browntown\djx | Out-Null
# Read Current CustomProperties for the user into memory
foreach ($userID in $idList){
$idNum = ($(Get-QlikUser -filter "userid eq '$userID'") | Where-Object {$_.userDirectory -eq 'BROWNTOWN'} ).id
# Build a string that represents the array Update-QlikUser requires for -customProperties
######### Needs a "if null" entry
$currCPvals = $(Get-QlikUser -filter "userid eq '$userID'" -full | Select-Object -Unique).customProperties
foreach ($currVal in $currCPvals) {
$curr = $currVal.definition.name + "=" + $currVal.value
$curr = '"' + $curr + '";'
$strNewCPvals += $curr
}
# Trim the trailing ; off the string ("array")
# $strNewCPvals = $strNewCPvals.replaceAll("; ","");
Write-Host ; Write-Host "======================================"; Write-Host
Write-Host $userID
Write-Host $strNewCPvals
# Build the new Update-QlikUser command
$newCMD = ( "Update-QlikUser -id " + $idNum + " -customProperties " + '@(' + $strNewCPvals + ')' )
Write-Host ; Write-Host "======================================"; Write-Host $newCMD
# Invoke-Expression $newCMD
## This needs to be separate from "log"
# $newCMD | Out-File -Append \\BROWNAS\ISOs\Qlik_Stack\"Scalability Tools"\logs\newCMD.ps1
# Log commands to file ("backup")
# Use iex to execute the prepared command
$current = $currentCPval.definition.name + "==>" + $currentCPval.value
Write-Host Current CPs for $currentCPval
Write-Host $current
$stringcpperuser += $current
}
# Update-QlikUser -id 36c5124e-e6db-4e14-8c3d-cd6e4b7fa714 -customProperties @("foo=test1";"foo=test2";"foo=test3";"foo=test4";"foo=test5")

26
trick.ps1 Normal file
View File

@@ -0,0 +1,26 @@
$UPNList = @(
'moe@stooge.com'
'larry@stooge.com'
'curly@stooge.com'
)
$UserGroupMembership = foreach ($UPN in $UPNList) {
if ($AzADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UPN'") {
if ($GroupList = Get-AzureADUserMembership -All $true -ObjectId $azAdUser.ObjectId) {
[PSCustomObject]@{
UPN = $UPN
GroupList = $GroupList.DisplayName
}
}
}
}
$GroupUserMembership = foreach ($GroupName in ($UserGroupMembership.GroupList | select -Unique)) {
[PSCustomObject]@{
GroupName = $GroupName
MemberList = ($UserGroupMembership | where GroupList -Contains $GroupName).UPN
}
}
$UserGroupMembership | FT -a
$GroupUserMembership | FT -a