Powershell ISE vs console (DSC executing)

Hello,

Can anybody tell me what is the difference between running DSC script by Powershell ISE vs standard console? When I run my script by PS ISE everything works fine, DSC applies to 2 servers incl. encryption. But when I run exactly the same script by “Run with Powershell” I’m getting such error messages:
System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception
exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
.

“line 1021 at , : line 1”

These errors point to the below line (in bold):
Configuration Config1
{



}
$configdata = @{
AllNodes = @(
@{
NodeName = “Server1”
PSDscAllowDomainUser = $true
CertificateFile = “$((Get-ChildItem “E:" | ? {$.Name -like “MyFolderName”}).fullname)\Server1.cer"
Thumbprint = ($Thumbs | ? {$
-like “Server1*”}).Split(”=”)[1]
}

@{
NodeName = “Server2”
PSDscAllowDomainUser = $true
CertificateFile = “$((Get-ChildItem “E:" | ? {$.Name -like “MyFolderName”}).fullname)\Server2.cer"
Thumbprint = ($Thumbs | ? {$
-like “Server2*”}).Split(”=”)[1]
}
)
}

The problem is with the Server2 (I’m running script on Server1). All paths are correct, can I use such syntax in the hashtable? the problem is with the standard powershell console, does anybody know why PS ISE does not return any errors?

The ISE maintains a more persistent environment than the console. At a guess, based on the error, $_ is a null expression when you’re running it, which makes me suspect E: doesn’t exist in that context.

I don’t know what to say :slight_smile: I’m sure E: drive as well as “MyFolderName” exist on the Server 2, I see it now. I tested it by execute command get-item "$((Get-ChildItem “E:" | ? {$_.Name -like “MyFolderName”}).fullname)\Server2.cer” on the Server2 with success.
Anyway if E: drive would not exist on the Server2 I guess PS ISE should also return an error.

Maybe there is some authentication/permissions difference when running DSC by ISE or standard console?