A user is having a PowerShell issue with the Invoke-CUQuery command. They are trying to use variables in a foreach, but the data property is empty. They asked for help with creating a script to move computers to a folder by username list. Another user suggested using export-cuquery to get all sessions and their computers.
Read the entire ‘Troubleshooting Invoke-CUQuery in PowerShell for Moving Computers to a Specific Folder’ thread below:
hi guys, i am having a powershell issue with the command Invoke-CUQuery.
this syntax would output correctly
(Invoke-CUQuery -Scheme "Main" -Table "Sessions" -Fields "sUserName", "sServerName" -Where "sUserName=’user1’").Data
in contrast, when i use a variable in a foreach, the data property is empty. tried a lot of variations like
(Invoke-CUQuery -Scheme Main -Table Sessions -Fields sUserName,sServerName -Where "sUserName=’$user’").Data
(Invoke-CUQuery -Scheme Main -Table Sessions -Fields sUserName,sServerName -Where "sUserName=""$user""").Data
(Invoke-CUQuery -Scheme Main -Table Sessions -Fields sUserName,sServerName -Where "sUserName=’$user’").Data
(Invoke-CUQuery -Scheme Main -Table Sessions -Fields sUserName,sServerName -Where ("sUserName='{0}’" -f $user)).Data
none of those works. i would really appreciate your help on this, thanks in advance 🙂
the end goal is to create a script that will move computers to a folder by usernames list.
in that case I wouldn’t do a search per user but use export-cuquery to get all sessions and their computers and do the move from there. I don’t have access to an environment atm so can’t check your exact syntax
Thanks a lot 🙂
Continue reading and comment on the thread ‘Troubleshooting Invoke-CUQuery in PowerShell for Moving Computers to a Specific Folder’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers