I have a script that I am building that will get the contents of a directory into a var, then populate another var with the information from the first var but modified. I am not getting any errors, but it’s not modifying the information the way I think it should. Not sure what I have wrong here.
The contents of the initial var look like this:
Name
jdoe.jpg
hdoe.jpg
jhancock.jpg
gwashington.jpg
Here is the script that I am using. In the foreach the $Identity var is never getting populated so it can’t process the command string that comes after.
[ul]
[li] The param block must be the first non-comment line of a script or function; you’ve got New-PSSession and Import-PSSession commands that would need to be moved into the Begin block. [/li]
[li] You’ve defined several variables as parameters in the param block, but they don’t appear to be actually used that way. You overwrite $Photo and $Identity inside the function without ever checking to see what values were passed in, and you appear to be making the assumption that $PhotoPath is automatically updated based on the values of $Path and $Photo each time $Photo is changed. (This is not the case; you would need to assign a new value to $PhotoPath each time.) [/li]
[li] You’re trying to access a .Photo property on the objects in your $Photo array, but that property doesn’t exist (which is why you’re seeing blank values for $Identity.) [/li]
[/ul]
Here’s a revision of your code, which is what I think you intended it to do:
Are you running the code that I posted, or has it been changed? I don’t see how you can be getting a blank $Identity variable from the code in my last post.
Then I’m not sure what’s going on. You’ll need to do some debugging (either by stepping through the code, or by adding some Write-Debug / Write-Verbose / etc statements.) See what the values of $File, $File.FullName, and $Identity are at the time that Import-RecipientDataProperty is about to be called.
Heh, I didn’t even notice the forum software was doing that. It’s translating the URL into an HTML element. It doesn’t look that way when I edit the post.
Just change that parameter back to its original value of: -ConnectionUri http://atlexmbx2/powershell , without all the HTML bits around it.