Hi all,
Firstly, apologies if this is in the wrong area.
I've written a simple script to copy AD Groups from one machine to another using the Active Roles Snapin. This works fine on computers with the snapin installed. I now need this to work for our Laptop Build team via Powershell remoting (invoke-command) who will be using the scripts on individual laptops when they have finished Ghosting them (which DON'T have the Active Roles snapin installed)
Ideally, i'd just like the script to run locally on the laptop and use the invoke-command to run the necessary QAD commands. Here's what I have so far:
__________________________________________
$LogFile = "<Log File Location>"
$PSS = New-PSSession <Server with QUEST snaping installed>
#Add-PsSnapin Quest.ActiveRoles.ADManagement
Invoke-Command -Session $PSS -ScriptBlock {Add-PsSnapin Quest.ActiveRoles.ADManagement}
$oldAsset = "oldasset"
$NewAsset = "newasset"
invoke-command -Session $PSS -Scriptblock { param($Groups2copy,$oldAsset) $Groups2Copy = Get-QADMemberOf(Get-QADComputer $Oldasset) | Select-Object -ExpandProperty Name} -ArgumentList $Groups2copy,$oldasset
invoke-command -Session $PSS -Scriptblock { param($Newcomp,$NewAsset) $NewComp = Get-QADComputer $Newasset} -ArgumentList $Newcomp,$Newasset
# Open Membership List and loop though
foreach($Group in $Groups2Copy)
{
invoke-command -Session $PSS -Scriptblock { param($Group,$Newcomp) Add-QADGroupMember -identity $Group -Member $NewComp} -ArgumentList $Group,$Newcomp
}
_____________________________________
On running this i receive a few errors, such as
"Object reference not set to an instance of an object.
+ CategoryInfo : NotSpecified: (:) [Get-QADComputer],NullReferenceException"
and
"Cannot validate argument on parameter 'Identity'. The argument is null or empty."
I'm guessing (or hoping!) that it's just a misuse of invoke-command or i'm not using it somewhere I should be. But ANY help someone can provide would be much appreciated. I feel like i've tried as many ways as possible to get this working but without success.
Thanks in advance
Scott