Though I’m not sure the regex solution will be simpler, it certainly is a powerful option.<\/p>\n
What are you trying to achieve?<\/p>","upvoteCount":0,"datePublished":"2018-06-07T18:56:38.000Z","url":"https://community.spiceworks.com/t/best-way-to-simplify/655890/4","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"
I apologize for this suggestion as I know your looking for a powershell way… but might be a whole lot easier to dump into Excel and just filter it out… just sayin…<\/p>\n
EDIT: Ohh your first post! Welcome to Spiceworks! Hope my comment didnt deter you away just trying to help you get a task accomplished as quickly as possible.<\/p>","upvoteCount":0,"datePublished":"2018-06-07T18:58:08.000Z","url":"https://community.spiceworks.com/t/best-way-to-simplify/655890/5","author":{"@type":"Person","name":"onecogmind","url":"https://community.spiceworks.com/u/onecogmind"}},{"@type":"Answer","text":"
\nI reduces the conditional operators (-and/-or) to just 4, logically groups what needs to be excluded and included and does the entire filtering in a single pipeline stage.<\/p>\n<\/blockquote>\n
I was just referring to the learning curve that comes with regex in the first place.<\/p>\n
The re-written code is excellent and has now been added to my local pile-o-code <\/p>","upvoteCount":0,"datePublished":"2018-06-07T20:45:54.000Z","url":"https://community.spiceworks.com/t/best-way-to-simplify/655890/7","author":{"@type":"Person","name":"psophos","url":"https://community.spiceworks.com/u/psophos"}},{"@type":"Answer","text":"
get-content \"C:\\Working\\Hardware Inventory Report.csv\" | Select -Skip 95 | Set-Content \"C:\\Working\\Invtemp.csv\"\nImport-CSV c:\\working\\invtemp.csv |Select @{N=\"Client\";E={$_.txt_HW_AssetsTable_CustomerName}},@{N=\"Type\";E={$_.txt_HW_AssetsTable_DeviceClass}},@{N=\"Device\";E={$_.Device_Name}},@{N=\"Model\";E={$_.\"Make_Model\"}},@{N=\"OS\";E={$_.Reported_OS}},@{N=\"LastUser\";E={$_.Last_Logged_In_User}},@{N=\"Checked\";E={$_.Last_Discovery_Date}} | \nwhere-object {($_.Type -NotLike \"Switc*\" -and $_.Type -NotLike \"Prin*\" -and $_.Type -NotLike \"othe*\" -and $_.Type -NotLike \"stor*\" -and $_.Type -NotLike \"*management*\") -or \n($_.Type -NotLike \"Generic Server\" -and $_.Device -NotLike \"SAN\"} | Sort Client | Export-csv C:\\Working\\hdinv.csv -NoTypeInformation\n<\/code><\/pre>\nSorry wrong code<\/p>\n
tulioarends,<\/p>\n
You still Rock Dude. I was looking at Regex, but I’m horrible when it comes to that.<\/p>","upvoteCount":0,"datePublished":"2018-06-08T18:09:30.000Z","url":"https://community.spiceworks.com/t/best-way-to-simplify/655890/8","author":{"@type":"Person","name":"ericrobinson7","url":"https://community.spiceworks.com/u/ericrobinson7"}},{"@type":"Answer","text":"
$devobj = \"*Datto*\",\"SAN*\",\"*QNAP*\",\"*barracuda*\",\"*controller*\" \n$OSobj = \"Linux NSM*\"\n$typobj = \"*Windows*\",\"*Server*\",\"*mac*\",\"*Management*\"\nget-content \"C:\\Working\\Hardware Inventory Report.csv\" | Select -Skip 95 | Set-Content \"C:\\Working\\Invtemp.csv\"\nImport-CSV c:\\working\\invtemp.csv |Select @{N=\"Client\";E={$_.txt_HW_AssetsTable_CustomerName}},@{N=\"Type\";E={$_.txt_HW_AssetsTable_DeviceClass}},@{N=\"Device\";E={$_.Device_Name}},@{N=\"Model\";E={$_.\"Make_Model\"}},@{N=\"OS\";E={$_.Reported_OS}},@{N=\"LastUser\";E={$_.Last_Logged_In_User}},@{N=\"Checked\";E={$_.Last_Discovery_Date}} | where-object {($_.Type -Like \"*Windows*\" -or $_.Type -Like \"*Server*\" -or $_.Type -Like \"*mac*\" -and $_.type -NotLike \"*Management*\")} | Where-object {($_.device -notlike \"*Datto*\" -and $_.device -notlike \"SAN*\" -and $_.device -notlike \"*QNAP*\" -and $_.device -notlike \"*barracuda*\" -and $_.device -notlike \"*controller*\" -and $_.OS -notlike \"Linux NSM*\")} |Sort Client | Export-csv C:\\Working\\Inventory.csv -NoTypeInformation\n<\/code><\/pre>\nwrong code above This is the correct code<\/p>","upvoteCount":0,"datePublished":"2018-06-08T18:14:08.000Z","url":"https://community.spiceworks.com/t/best-way-to-simplify/655890/9","author":{"@type":"Person","name":"ericrobinson7","url":"https://community.spiceworks.com/u/ericrobinson7"}},{"@type":"Answer","text":"\n\n
<\/div>\n
ericrobinson7:<\/div>\n
\n$devobj = \"*Datto*\",\"SAN*\",\"*QNAP*\",\"*barracuda*\",\"*controller*\" \n$OSobj = \"Linux NSM*\"\n$typobj = \"*Windows*\",\"*Server*\",\"*mac*\",\"*Management*\"\nget-content \"C:\\Working\\Hardware Inventory Report.csv\" | Select -Skip 95 | Set-Content \"C:\\Working\\Invtemp.csv\"\nImport-CSV c:\\working\\invtemp.csv |Select @{N=\"Client\";E={$_.txt_HW_AssetsTable_CustomerName}},@{N=\"Type\";E={$_.txt_HW_AssetsTable_DeviceClass}},@{N=\"Device\";E={$_.Device_Name}},@{N=\"Model\";E={$_.\"Make_Model\"}},@{N=\"OS\";E={$_.Reported_OS}},@{N=\"LastUser\";E={$_.Last_Logged_In_User}},@{N=\"Checked\";E={$_.Last_Discovery_Date}} | where-object {($_.Type -Like \"*Windows*\" -or $_.Type -Like \"*Server*\" -or $_.Type -Like \"*mac*\" -and $_.type -NotLike \"*Management*\")} | Where-object {($_.device -notlike \"*Datto*\" -and $_.device -notlike \"SAN*\" -and $_.device -notlike \"*QNAP*\" -and $_.device -notlike \"*barracuda*\" -and $_.device -notlike \"*controller*\" -and $_.OS -notlike \"Linux NSM*\")} |Sort Client | Export-csv C:\\Working\\Inventory.csv -NoTypeInformation\n<\/code><\/pre>\nwrong code above This is the correct code<\/p>\n<\/blockquote>\n<\/aside>\n
Do you still need help with this? I don’t mind sorting this out.<\/p>\n
If so let me know if you want it optimized for speed or readability.<\/p>","upvoteCount":0,"datePublished":"2018-06-11T13:29:29.000Z","url":"https://community.spiceworks.com/t/best-way-to-simplify/655890/10","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}}]}}
Neally
(Neally)
June 7, 2018, 5:36pm
2
Welcome.
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don't say "Need help" or "PowerShell Help", actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…
Can you share the entire code? Sometimes you can filter as well.
It’s tough to say if you can simplify it.
1 Spice up