Running a script with the checkbox for pass AD credentials checked $ADUsername and $ADPassword

First off let me say that I am not a powershell or scripting person.  

I have a script that runs just fine in administrator mode powershell on the host.  If I try to run it as a Nerdio scripted action it fails because the system user is not allowed.

What should my Nerdio script look like to use the passthru variables?  Here is the script that runs just fine in PowerShell.

Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}

 

Thanks in advance

0

Comments (2 comments)

Avatar
DStephenson

Welcome to the community, Robert Shoemaker! 🙂

I know we have run that command on our host image but haven't needed to run it on production hosts.
I modified a different script to work with Nerdio (see Use Nerdio Scripted Action to Update Active Directory – Nerdio Help Center (getnerdio.com)) and admin credentials that worked for that use case.
NOTE: I'm no PowerShell/Scripting person either.😄

That being said, you could do something like the following:

[pscredential] $domaincred = New-Object system.management.automation.pscredential ($ADUsername,(convertto-securestring $ADPassword -asplaintext -force))

Invoke-Command -ScriptBlock {
    Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {
        Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"
    }
} -Credential $domaincred

 

If that doesn't work, I'm thinking someone else with a bit more Nerdio/PowerShell knowledge may be able to chime in on what we're missing. 🤔🤞

1
Avatar
Robert Shoemaker

Thanks Dave, I'll try it and let you know. 

1

Please sign in to leave a comment.