Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell Script to import photos

$
0
0

Hi,

Im fairly new to powershell but am looking to create a script which can look in a directory of photos which are namedsamaccountname.jpg. What I want to do is run a script which looks at the filename, matches it to samaccountname and import the photo.

This is what I have so far, but as I expected I am having issues:


$SAM = Get-Mailbox | select samaccountname
$Files = Get-ChildItem c:\photos | Select-Object Name
$Path = "C:\Photos\$SAM.jpg"

foreach ($file in $files) {([Byte[]] $(Get-Content -Path "$SAM" -Encoding Byte -ReadCount 0))}

Get-Content : Could not find a part of the path 'C:\Photos\'.
At C:\Photos\photo1.ps1:4 char:40
+ foreach ($file in $files) {([Byte[]] $(Get-Content -Path "$SAM" -Encoding Byte - ...
+                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Photos\     ...               :String) [Get-Content], DirectoryNotFo
   undException
    + FullyQualifiedErrorId : GetContentReaderDirectoryNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand

Looks like it is not concatenating the path correctly. Any ideas what I can do?

Cheers


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>