logo

The ConnectWise Control forum has moved to ConnectWise University! This forum has been locked and is in read-only mode. Click here for instructions on how to access the new forum.

Welcome Guest! You can not login or register.

Notification

Icon
Error

Options
Go to last post Go to first unread
17GSupport  
#1 Posted : Tuesday, May 3, 2016 8:28:20 AM(UTC)
17GSupport


Rank: Newbie

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 6/9/2014(UTC)
Posts: 10
United Kingdom
Location: London

Was thanked: 2 time(s) in 1 post(s)
Hi

I have a powershell script that runs a load of WMI queries and and exports the results to a csv. This gets run on every new PC that we deploy and displays information such as machine name, last logged on user, serial, memory, cpu, make, model, OS etc etc. What would be really handy is if there was a way we can highlight all on-line screen connect machines and using the command toolbox run the same powershell script to get that info. Here is the command I am running:

powershell -ExecutionPolicy Bypass -command "& '\\UNCPath\UpdateInventory.ps1'

But it fails with this error:
& : The term '\\UNCPath\UpdateInventory.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:3 + & '\\UNCPath\UpdateInventory.ps1 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (\\UNCPath\UpdateInventory.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

I can run powershell commands no problem but cant seem to run scripts

any suggestions?

Thanks

powellap  
#2 Posted : Tuesday, May 3, 2016 3:08:13 PM(UTC)
powellap


Rank: Advanced Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 2/16/2014(UTC)
Posts: 99
United States

Thanks: 3 times
Was thanked: 8 time(s) in 7 post(s)
Probably the & needs to be escaped so that it doesn't try to split the command into two lines.


http://www.robvanderwoude.com/escapechars.php

I don't understand why you have a single double quote with the & so I didn't mess with it...
Maybe something like...?

powershell -ExecutionPolicy Bypass -command "^& '\\UNCPath\UpdateInventory.ps1'

Edited by user Tuesday, May 3, 2016 3:26:35 PM(UTC)  | Reason: Not specified

thanks 1 user thanked powellap for this useful post.
Mike on 5/4/2016(UTC)
17GSupport  
#3 Posted : Tuesday, May 3, 2016 3:28:34 PM(UTC)
17GSupport


Rank: Newbie

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 6/9/2014(UTC)
Posts: 10
United Kingdom
Location: London

Was thanked: 2 time(s) in 1 post(s)
Bingo thanks for the input. This is what works:

powershell -ExecutionPolicy Bypass -command \\UNCPath\UpdateInventory.ps1
AustinKnight  
#4 Posted : Tuesday, May 3, 2016 11:21:21 PM(UTC)
AustinKnight


Rank: Advanced Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 5/16/2012(UTC)
Posts: 307
Location: Oregon

Thanks: 62 times
Was thanked: 10 time(s) in 10 post(s)
Would you be willing to share your script?
JASON T. AUSTIN
Lead Network Engineer
Falcon Development, Inc.
www.falcondevelopment.com

17GSupport  
#5 Posted : Wednesday, May 4, 2016 8:11:16 AM(UTC)
17GSupport


Rank: Newbie

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 6/9/2014(UTC)
Posts: 10
United Kingdom
Location: London

Was thanked: 2 time(s) in 1 post(s)
Sure. my script is here: http://pastebin.com/nVr6eAHq

Bit rough around the edges but works and is now in my command box so i can run against screenconnect machines.

The only issue I have is with machines checked in with screenconnect but off site so cant map to the UNC path. Would anyone have any suggestions of how i can get around this? could I use the the powershell script to generate the report on the screenconnect server for example? that way it doesn't matter where the machine is.
thanks 2 users thanked 17GSupport for this useful post.
AustinKnight on 5/4/2016(UTC), Mike on 5/4/2016(UTC)
AustinKnight  
#6 Posted : Wednesday, May 4, 2016 4:56:03 PM(UTC)
AustinKnight


Rank: Advanced Member

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 5/16/2012(UTC)
Posts: 307
Location: Oregon

Thanks: 62 times
Was thanked: 10 time(s) in 10 post(s)
You could use a utility like "SENDITQUIET" to email the csv file. I use this approach to gather data from the SC Command line. Hope this helps, by the way thanks for the script!
JASON T. AUSTIN
Lead Network Engineer
Falcon Development, Inc.
www.falcondevelopment.com

thanks 1 user thanked AustinKnight for this useful post.
Mike on 5/4/2016(UTC)
17GSupport  
#7 Posted : Wednesday, May 11, 2016 8:39:38 AM(UTC)
17GSupport


Rank: Newbie

Medals: Level 1: Random Act of Kindness! Received One Thanks!

Joined: 6/9/2014(UTC)
Posts: 10
United Kingdom
Location: London

Was thanked: 2 time(s) in 1 post(s)
Originally Posted by: AustinKnight Go to Quoted Post
You could use a utility like "SENDITQUIET" to email the csv file. I use this approach to gather data from the SC Command line. Hope this helps, by the way thanks for the script!


Can you give me an example of how this works?
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.