tech-man Posted November 6, 2015 Posted November 6, 2015 Hello Can someone help me debug this script? Need a script to read a CSV and run a command to add print credit to users. I've given an example command line which works. Thanks $Users = Import-Csv -Path "$env:USERPROFILE\Desktop\credit.csv" ForEach ($User in $Users) { $Parameters = @{ Credit = $User.Credit Comment = $User.Comment User = $User.Username } Write-host @Parameters # "c:\Program Files\PaperCut MF\server\bin\win\server-command.exe adjust-user-account-balance" @Parameters # EXAMPLE command with parameters "c:\Program Files\PaperCut MF\server\bin\win\server-command.exe" adjust-user-account-balance "TESTUSER" 1.00 "Add £1" }
halbaradkenafin Posted November 6, 2015 Posted November 6, 2015 You should just be able to put a & before the command line you want to run and it should work.
tech-man Posted November 6, 2015 Author Posted November 6, 2015 I dont think the command line para's are being passed in the format that I need.....
Jawloms Posted November 6, 2015 Posted November 6, 2015 What are you trying to achieve? Presumably something you can't do in PaperCut's gui?
tech-man Posted November 6, 2015 Author Posted November 6, 2015 Add different amounts of credit to users worked out by a excel formula....
halbaradkenafin Posted November 6, 2015 Posted November 6, 2015 When you Write-Host them I'd imagine they come out in a different order each time it's ran? You'll need to use an Ordered hashtable to fix that or not bother with the hashtable at all and just specify them in the command line, possibly in a format like this: & "c:\Program Files\PaperCut MF\server\bin\win\server-command.exe adjust-user-account-balance" "$($User.Username) $($User.Credit) $($User.Comment)" I'd probably use this method as I recall spaltting a hashtable into command tags on the full hashtable including parameter names so that might be screwing it up.
tech-man Posted November 6, 2015 Author Posted November 6, 2015 Thanks username & command need to be enclosed in "" how can I do this?
halbaradkenafin Posted November 6, 2015 Posted November 6, 2015 Thanks username & command need to be enclosed in "" how can I do this? Use "$($User.Username)" $User.Credit "$($User.Comment)" and that should work.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now