Updated Script for v8.0 - It outputs the names of the items as it deletes too.
This looks like it's working just fine in our 7.6 environment. We decided to delete all computers and let them re-import via AD and agent check-in. We've upgraded from 7.1 to 7.5 and now 7.6 and are finally ready to start pushing this to full production and wanted a clean DB, but didn't want to reconfigure all our settings, filters, and policies.
Used the following query:
SELECT Guid FROM vCMDBComputer
Didn't realize in 7.6 you can simply use filters under Manage > computers to search all computers, then select whatever you want(yes multiples) and delete! :) Much safer/easier.
Ran a test job this morning but it's not working on 7.6.
D:\Program Files\Altiris\Notification Server\Bin>NScript.exe DeleteItems.cs Deleting Items... Deleting 447 items. 0 deleted
Trying to troubleshoot now, I'm not familiar with C so I don't have a clue if I need to change anything.
Specifically, this is the select statement I'm trying to use in the .cs file. I tried a single GUID as well but same error.
static public string sql = @"SELECT GUID FROM vComputer WHERE IsManaged=0 and [os name] = 'mac os x'";
I'm going to test it tomorrow on 7.6 because I need to purge over 1000 unmanaged computers. Will post my findings tomorrow.
7.5 compatible?? Dont have a dev environemnt to test on.
Anyone have a retire computers from file script...
NS 7.1.8280
I am trying to delete all the unmanged computers using the following SQL command SELECT Guid FROM vComputer WHERE IsManaged = 0. I am running from the default location of nscript.exe and running under the application user id. The script starts and shows that it will be deleting 491 items (this is the number I expected). After a few minutes, I get the following error:
* The script threw an exception. Message: Failed to connect to the local NS communications group.
Stack Trace: ============ at Altiris.NS.Server.GetNSChannel() at Altiris.NS.GroupCommunications.NSSharedCache`2..ctor(Int32 maxSize, String cacheName, Boolean filtering) at Altiris.NS.ItemManagement.Item.EnsureItemCacheExists() at Altiris.NS.ItemManagement.Item.GetItemFromCache(Guid itemGuid) at Altiris.NS.ItemManagement.Item.GetItemInternal(Guid itemGuid, IEnumerable` 1 accessPermissions, ItemLoadFlags itemLoadFlags) at Altiris.NS.ItemManagement.Item.GetItem[T](Guid itemGuid, IEnumerable`1 acc essPermissions, ItemLoadFlags itemLoadFlags) at Altiris.NS.ItemManagement.Item.GetItem[T](Guid itemGuid) at Altiris.NS.ItemManagement.Item.GetItem(Guid itemGuid) at DeleteItems.DeleteSQLResults(String sql) at DeleteItems.Main(String[] args)
============================================ Errors occurred. Press the enter key to exit ============================================
Any ideas?
Problem solved finally, it required to use the application identify to log in the server to perform the task.
But any ideas how to write the SQL if I have a large amount of machines, which i only have the computer names ?
Thanks.
Hi KSchroeder,
It is running same as the original script with adding the SQL, and it is running within the server admin command prompt.
Here is my script:
Jonouil,
I would be sure that you are running the command in an elevated command prompt on the SMP server, preferably using the Application Identity account to logon to the SMP server. Your query should not specify the database directly; just run it as above; you shouldn't need to have a "USE <database>" command or fully-quality the table references in the query.
Hi, I trying to use this but it seems cannot connect our database, as we are using a out of box DB.
Here are the result after the scripts ran:
Can also confirm that this works fine on 7.1 SP2; I used it to purge computers created via AD Import.
This is great. It needs lots of red flags and warnings, becuase you could do real damage. With great power comes great responsibility.
NScript.exe uses the NS database settings so it will connect to a remote SQL server...
how do i run from default location of the script which is NS and my DB is on separate box ..will the script automatically connect to remote DB system and execute the script ?
You have to run it from the default location - I believe it's hardcoded...
I copied the nscript.exe and nscript.exe.config from NS to db server.. then i tried to execute the abve script and gave me following error... need help !!! to set it right.
D:\Altiris\Altiris_Bulk_delete_script\DeleteItems>nscript.exe DeleteItems-1resource.cs
* The script file "Altiris.Common, Version=6.0.0.0, Culture=neutral, PublicKeyTo ken=d516cb311cfb6e4f" could not be read
D:\Altiris\Altiris_Bulk_delete_script\DeleteItems>
Hi .. i hav modified the script and put the above query to delete one resource. Now want to check how do I run the script as DB is on the separate server and to execute this script i need nscript.exe which is on notification server ...so can I just simply copy nscript.exe on DB server and execute the nscript.exe deleteitems.cs ??
Regards/Nitin
You mean I should put following query in the script to test deletion of 1 resource before going for big one.
select vc.guid from vcomputer vc where vc.[ismanaged] = 0 and Server = [server name] and IsLocal = 1 where vc.guid = "7BCCA983-4A92-4675-B281-022AC04E03C5 "
is this right query to be put in the script ? or do I have to include few other tables apart from vcomputer in the query?? and will this script remove all relevant entries/links of unmanaged resources ?
Thanks a lot again !
Does this work?
'SELECT Guid FROM vComputer WHERE IsManaged = 0' BTW, we will not be able to provide a SQL script that will completely remove all these unmanaged resources...it needs to be done through the C# code provided above. Let's figure out the SQL needed to find all these resources and then let the script do the rest...
I am looking for deleting approx 12000 unmanaged resources which got in during AD import. How do I use this SQL script to remove these clients. Can someone please help in modifying this SQL script with right queries inside which i can just go and run on the SQL server...atleast for few devices 1st.
Thanks in advance !
Have you tested in 7.0?
That is the correct location to specify your SQL query.
Great query, thank you for providing this!