Questions about adding image to thumbnailphoto attribute from Active Directory - sharepoint

I've been using adldap to add user image to the thumbnailphoto attribute for updating user profile information through active diectory.
Here is what i did as follows:
I use code:
$modified = $adldap->user()->modify($account, $attributes );
to update the user account with specific attributes (ex. thumbnailphoto)
however, when I add information to $attribute.
I convert the image url to base64 string ( ex. "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAg.......")
and then decode those string and update to $attributes. even though the thumbnailphoto attribute has value, but it can't display real image (i checked with software name "AD photo edit free edition")
the decoded value i got as follows:
"\u00c3\u0083\u00c2\u00bf\u00c3\u0083\u00c2\u0098\u00c3\u0083\u0......"
Which I compared with other user active directory thumbnailphoto attribute, their image display perfectly .
their thumbnailphoto attribute value is as follows:
"\u00ff\u00d8\u00ff\u00e0\u0000\u0010JFIF\u0000\u0001\u0001\u0001......"
I think those are hexdecimal value , and i try to convert my original encode value("/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAg.......")) into hex and update to the thumbnailphoto attribute and turn out to be
"\ffd8ffe0..... "
but still not similar to the one that I got from the other users
Just wondering , what is the correct way to update image to active directory
Thanks

I am using windows PowerShell for this one,
My code:
# Set the network path of the user pictures.
$NetworkPath = "Path were the photos are stored"
# Get all the filesnames without the extension, every picture inside this folder should be named after the username of the user.
$UsersNames = Get-ChildItem -Path "$NetworkPath"| % {$_.BaseName}
# For each file name (username) go and convert into digital (byte encoding) the file then store it in a temporary value ($Photo).
# Then update the users jpegPhoto attribute on Active Directory with the $photo
foreach ($User in $UsersNames){
$Photo = [Byte[]](Get-Content "$NetworkPath\$User.jpg" -Encoding Byte)
Set-ADUser $User -Replace #{jpegPhoto=$Photo}
}
Get-ChildItem 'C:\Setup\Test\*.jpg' | Set-ImageSize -Destination 'C:\Setup\Test\new\' -WidthPx 96 -HeightPx 96 -Verbose
I had to download the Set-ImageSize so I can resize the images.
https://gallery.technet.microsoft.com/scriptcenter/Resize-Image-File-f6dd4a56
The script explains itself I hope this is informative for you.

Related

create PowerShell script to update environment variable using a JSON or Excel file

I have a VDI setup in Azure and have users in two regions however I need to create a login script, ideally in PowerShell
The login script will update users' environment variables. Now the tricky part, I will need this script to pull the information from a file, JSON or Excel. Ideally a JSON file.
I want it to check for the heading of Variable name and Variable value from the JSON file.
Now depending on the region of the virtual server, I would want only variables updated for the user if they are in North East and have a set of variables for users in South Coast
If you are trying to load a file from the local file system :
You can load the content into the memory and then convert it to custom object to do further manipulation.
$text = Get-content "<YOUR PATH TO THE JSON FILE>\<FILENAME>.json"
$json = $text | ConvertFrom-Json
If your JSON File is present in an endpoint or so. You can do a invoke-webrequest
$response = Invoke-WebRequest "https://yourendpoint.com/filename.json"
$content = $response.Content
$json = $content | ConvertFrom-Json
Sample output / Sample Usage :

Remove end of Line Comma from a Azure data lake store File

I need some inputs on file processing in Azure Data lake storage using Power Shell.
I have a pipe Delimited input file in my ADLS Gen 1 Account.
The File content looks like below
1|2|3|a,b,
3|4|5|d,h,
I am able to remove last comma using powershell in my Local PC using below code
Get-Content $file_name | ForEach-Object {$_.TrimEnd(",") }
But when i run the same query against the same file in Azure Data lake Storage Gen 1 Account nothing happen to the data . The code i am using is
Get-AzureRmDataLakeStoreItemContent -Account $accountName -Path $myrootdir/path/test.csv| ForEach-Object {$_.TrimEnd( ",") }
One observation i have is that ForEach-Object is returning only once. That is if i print hello inside ForEach-Object loop it prints only one. But i verified that there is no new line problem by running -Head and -Tail command. I am attaching a screenshot for the same.
Can you please help me to understand what i am doing wrong here and any alternative to remove last comma in each line.
I don't think you can modify the store item directly via powershell.
The Get-AzureRmDataLakeStoreItemContent just gets the content. (Based on my experience, if it allows you to do that, it should be a command like Set-AzureRmDataLakeStoreItemContent orUpdate-AzureRmDataLakeStoreItemContent)
The workaround is to export the file -> modify it in local -> import it again.
Update:
If I do not misunderstand your question, try the command below.
((Get-AzureRmDataLakeStoreItemContent -AccountName "joydatalake1" -Path "/sss/test.csv").ToString() -split("`r")).Trim() | ForEach-Object {$_.TrimEnd(",")}

Showplan XML link in Excel worksheet?

I'm writing a tool that summarizes SQL Server performance information in an Excel spreadsheet. Some of that information includes SQL Server execution plans, which can be encoded in XML. (This is referred to as "showplan XML".) SQL Server Management Studio recognizes files containing these XML documents and can display them graphically. My question is whether it's possible to create a hyper-linked cell in Excel that opens a plan in Management Studio.
I've never done this sort of thing before. (My background is in writing Unix system software.) It looks like the DDE (Dynamic Data Exchange) protocol could hold the answer, so that is the approach I am currently investigating.
This turned out to be very straightforward once I figured out how to do it. Instead of DDE, I used OLE embedding. Embedding turns the Excel workbook into something similar to a Unix tar file or a Windows zip file: you have one file that contains other files within it.
First I write the XML text to a temporary file, with a .sqlplan extension. Second, I call this code:
$object = $ws.OLEObjects().Add(
[System.Type]::missing, # ClassType
$path, # FileName
$false, # Link
$false, # DisplayAsIcon
[System.Type]::missing, # IconFileName
[System.Type]::missing, # IconIndex
[System.Type]::missing, # IconLabel
[System.Type]::missing, # Left
[System.Type]::missing, # Width
[System.Type]::missing, # Height
[System.Type]::missing # Top
)
Where $path points to the temporary file. Third, I delete the temporary file. (Because the "Link" parameter is $false, a copy of the XML file is now part of the workbook.)
This may be what Martin Smith was suggesting with his comment above, but at the time I understood him to be saying that the .sqlplan files would be stored outside of the workbook as normal files. Also note that this would probably work with any sort of file you would like to embed in a spreadsheet!
The reason I don't set the size and position at creation time is because you can't make it anything but a square at that point. I follow the code above with this, to make the "link" fill the cell it's in:
$object.ShapeRange.LockAspectRatio = $false
$cell = $range.Cells($cellRow, $cellColumn)
$object.Left = $cell.Left
$object.Width = $cell.Width
$object.Height = $cell.Height
$object.Top = $cell.Top

Filename of the excel file upon downloading in Codeigniter

Is it possible to set the filename of a excel to a name from database upon downloading ?
Your question is not precise, but I guess, probably you want to set the name of an Excell's file possible to download from your page to the name saved in the database.
In CodeIgniter it's possible to use Download Helper.
First select from the DataBase the name you want to show for users and save it to a variable. For example:
$name.
Load Download Helper:
$this->load->helper('download');
Use function force_download() to serve your Excel file for user with your name from DB:
$data = file_get_contents($excell_file_path); // Read the file's contents
force_download($name, $data);

Magento: "Image does not exist"

I'm importing a CSV file in Magento (version 1.9).
I receive the error: 'Image does not exist'.
I've tried to do everything I could find on the internet.
The template I'm using for upload is the default template taken from my export folder.
I've added the / before the image name and I've also saved the file as UTF-8 format.
Any advice would help.
Use advanced profiler
System > Import/Export > Dataflow – Profiles
You only need to include the attributes that are required, which is just the SKU. Plus the appropiate image attributes. Plus labels if you want to go all out.
When you are creating your new profile, enter the following settings:
Now you can hit save! With our Profile now complete, we just need to create the folder media/import. This is where you will be storing all your images awaiting import.
When uploading images, they need to be within a folder called media/import. Once saved to that folder you can then reference them relatively. By that I mean if your image is in media/import/test.jpg in your csv reference it as /test.jpg. It’s as easy as that.
Please check this link for more information
Import products using csv
in the Default Import
first move all the images in media/import folder and then use '/imagename' in csv and then import.
And give the 777 permission to the import folder.
Let me know if you have any query....
check 3 point before upload csv file in Magento
create media > import folder and place all images inside import
folder import folder should have 777 permission
the path of images should be /desert-002.jpg
It may issue with image path in CSV if a image path in CSV is abg/test.jpg then it path in Dir is ..media/import/abg/test.jpg.also check image extension letter issue. Suppose your image extension I'd JPG and you rewrite in CSV is jpg .then it show image not exits
Your file template must look like this:
sku,image
product-001,/product_image.jpg
This file must exist: yourdocroot/media/import/product_image.jpg
More detail please read this method:
Mage_Catalog_Model_Convert_Adapter_Product::saveImageDataRow
You will see these lines:
$imageFile = trim($importData['_media_image']);
$imageFile = ltrim($imageFile, DS);
$imageFilePath = Mage::getBaseDir('media') . DS . 'import' . DS . $imageFile;
I hope this help!!!

Resources