Need help with PowerShell script

t_ski

Supreme [H]ardness
Joined
Jun 13, 2006
Messages
7,506
I've been handed responsibility for a backup system that utilizes EMC Networker. I just found out that I have a HUGE amount of old save sets that need to be deleted manually (somewhere in the 10-20,000 range), so I'm hoping to do this with a script.

I can output the save set IDs to a CSV file like this:

mminfo -ot -xc, -q "savetime<3 months ago" -r ssid,client,name,totalsize,savetime >C:\Over90days.csv

The "-r" switch allows me to determine what info I want in each column, and I can change the "savetime" value as needed. Column 1 of the CSV file will have the SSID, which is a - to 11 digit number like "975486124."

I tried the following as a PS script:

Code:
$1 = Import-CSV C:\Over90days.csv

Foreach ($ssid in $1)
{
nsrmm -y -d -S $ssid
}

Powershell does not like the ssid value, and I get the following for each SSID number in the CSV file:

91383:nsrmm: '@ssid=975486124}' is not a valid save set ID.

usage: nsrmm [-v | -q] [-s server] [-f device]
or nsrmm -l [-v | -q] [-s server] [-f device] [-myB]
[-e forever] [-c capacity] [-o mode] [-b pool] [-R | volume]
or nsrmm {-u | -j} [-v | -q] [-s server] [-y] [-f device | volume...]
or nsrmm -p [-v | -q] [-s server] [-f device]
or nsrmm -m [-v | -q] [-s server] [-f device] [-r] [volume]
or nsrmm -H -f device [-v | -q] [-s server] [-y]
or nsrmm -E -f device [-v | -q] [-s server] [-y]
or nsrmm {-d | -o mode} [-v | -q] [-s server] [-Py]
[-S ssid[/cloneid] | -V volid | volume...]
or nsrmm [-s server] -S ssid {-w browsetime | -e retentiontime} [-y]
or nsrmm -x [-s server] [-v] {-V source_volid destination_volid | source_volume destination_volume}

I know if I manually run the command as
Code:
nsrmm -y -d -S <insert_ssid#here>
...it works fine.

Thanks in advance for any assistance you can provide.
 
Do you want us to make a script, or help you learn how to make your own? :)

You import the CSV and then you're trying to jump into a loop from that variable... you define a new variable ($ssid) in the process as well. I'll start by assuming that you want help to learn and not just the solution, so I'll just say that you skipped a couple of steps :).
 
I've been handed responsibility for a backup system that utilizes EMC Networker. I just found out that I have a HUGE amount of old save sets that need to be deleted manually (somewhere in the 10-20,000 range), so I'm hoping to do this with a script.

I can output the save set IDs to a CSV file like this:

mminfo -ot -xc, -q "savetime<3 months ago" -r ssid,client,name,totalsize,savetime >C:\Over90days.csv

The "-r" switch allows me to determine what info I want in each column, and I can change the "savetime" value as needed. Column 1 of the CSV file will have the SSID, which is a - to 11 digit number like "975486124."

I tried the following as a PS script:

Code:
$1 = Import-CSV C:\Over90days.csv

Foreach ($ssid in $1)
{
nsrmm -y -d -S $ssid
}

Powershell does not like the ssid value, and I get the following for each SSID number in the CSV file:



I know if I manually run the command as
Code:
nsrmm -y -d -S <insert_ssid#here>
...it works fine.

Thanks in advance for any assistance you can provide.

Let's look at your script:

Code:
$1 = Import-CSV C:\Over90days.csv

Foreach ($ssid in $1)
{
nsrmm -y -d -S $ssid
}


It seems as if you're trying to get Power Shell to do what can probably best be done in a simple batch file.

https://community.emc.com/docs/DOC-24033 shows you how to accomplish what you want with a batch file.

Don't underestimate DOS Batch files. I've migrated 2.9 million files from our Command's shared network drive using a 1 line DOS Batch command very similar to the command listed in the link.




Editing to add the command I use to archive old data from our network shares and how it can be used with your input file to accomplish what you want

Code:
for /f "delims=" %%i in (B3Input.txt) do echo F|xcopy "U:\%%i" "F:\B3\%%i" /c /i /z /y

Try placing the name of your csv file in the parentheses and replace the XCOPY command and switches with your nsrmm command and switches
 
Last edited:
Do you want us to make a script, or help you learn how to make your own? :)

You import the CSV and then you're trying to jump into a loop from that variable... you define a new variable ($ssid) in the process as well. I'll start by assuming that you want help to learn and not just the solution, so I'll just say that you skipped a couple of steps :).

Yes, I know something's missing, or else it would have worked :)

I suppose I should have prefaced this by saying I'm not at all familiar with writing PowerShell scripts (which is probably evident by my script above), and I am only slightly more familiar with running them. Most of the ones I've used were written by a former co-worker who was a genius at scripting, and the rest were flat-out copies from instructions.

I am more familiar with batch scripts, and have written about a hundred or so very simple ones, mostly to apply Windows event log fixes, or some slightly more advanced menu scripts or mass program installs. But even with that, I'm still no programmer.

I wouldn't mind an answer but I would prefer an answer with a clear explanation in order to learn more.

Let's look at your script:

Code:
$1 = Import-CSV C:\Over90days.csv

Foreach ($ssid in $1)
{
nsrmm -y -d -S $ssid
}


It seems as if you're trying to get Power Shell to do what can probably best be done in a simple batch file.

https://community.emc.com/docs/DOC-24033 shows you how to accomplish what you want with a batch file.

Don't underestimate DOS Batch files. I've migrated 2.9 million files from our Command's shared network drive using a 1 line DOS Batch command very similar to the command listed in the link.




Editing to add the command I use to archive old data from our network shares and how it can be used with your input file to accomplish what you want

Code:
for /f "delims=" %%i in (B3Input.txt) do echo F|xcopy "U:\%%i" "F:\B3\%%i" /c /i /z /y

Try placing the name of your csv file in the parentheses and replace the XCOPY command and switches with your nsrmm command and switches

Thanks for this. I was not sure if a batch file could call another file for input, which is why I was pursuing the PowerShell option. I've got a small file I'm working against to test my script, and when I'm satisfied with it I plan to apply it to the larger list.
 
Can I make a general point? Until you know the script actually works, don't let it delete anything. Rather than working against a small file, let it report what it would delete. You don't want to accidentally delete everything.
 
Can I make a general point? Until you know the script actually works, don't let it delete anything. Rather than working against a small file, let it report what it would delete. You don't want to accidentally delete everything.

Just to follow up on this comment...

Use the -whatif switch to simulate the script running so it won't actually do whatever action you're attempting
 
Not sure if you've got this working -- but it seems to me like you don't a properly formatted csv. Is it just a one column list with the values in it? If you need help still, put the first few lines of the csv up for display. You should be able to easily do this with powershell..

I'm not discounting batch, I still use it all the time...
 
It was multiple columns with a header across the top (headers are the options listed in the script that created the CSV file).

I was able to get this done with the page notarat posted. I have cleaned up some of the files with that script, and will probably return to do additional cleanup at a later point. Consider this resolved. Thanks to all who posted!
 
Back
Top