lookup file name in sql and rename fileCannot start SQL Server PowerShellRename file in folder whenever it's...

What do Xenomorphs eat in the Alien series?

Gantt Chart like rectangles with log scale

Instead of Universal Basic Income, why not Universal Basic NEEDS?

Who is flying the vertibirds?

Are there other languages, besides English, where the indefinite (or definite) article varies based on sound?

The difference between「N分で」and「後N分で」

My adviser wants to be the first author

Is it normal that my co-workers at a fitness company criticize my food choices?

Identifying the interval from A♭ to D♯

How do anti-virus programs start at Windows boot?

Sailing the cryptic seas

How to write cleanly even if my character uses expletive language?

Are there verbs that are neither telic, or atelic?

A link redirect to http instead of https: how critical is it?

Do I need life insurance if I can cover my own funeral costs?

Could the Saturn V actually have launched astronauts around Venus?

Why one should not leave fingerprints on bulbs and plugs?

Official degrees of earth’s rotation per day

Life insurance that covers only simultaneous/dual deaths

Gravity magic - How does it work?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Why do passenger jet manufacturers design their planes with stall prevention systems?

Can I use USB data pins as power source

how to write formula in word in latex



lookup file name in sql and rename file


Cannot start SQL Server PowerShellRename file in folder whenever it's created?Kill process, then uninstall application--Can I do this with PowerShell, over 400 computers, from a txt file?Rename displayName and CN from givenName and surName with Powershell?PowerShell won't rename an export .csv fileHow to retrieve list of unique file name parts?Powershell DSC File copy - Workgroup machinesPowershell privileges and execution policyRename AD computer member fails with “Cannot create a file when that file already exists”Delete file with powershell first 2 characters of the file name are the same













0















I am trying to use a Powershell script to use the account number in a file name and re-name with the ID number from a sql database. Below is the code I am using to attempt this and I am not getting the results I need. Please let me now if you have any suggestion or advise in getting this to work.



Thanks!!



File name = 111119999.docx



Table =



ID AccountNumber



5555 111119999



## Select Data from Database

function Select-Info($CliRef)
{
$conn = new-object System.Data.SqlClient.SqlConnection
$connstring = “provider=sqloledb;data source=[vmsvr039];initial catalog=[crs5_oltp];integrated security=SSPI”
$conn.connectionstring = $connstring

$conn.open()
$query = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn)
$cmd.connection = $conn
$cmd.commandtext = $query
$result = $cmd.executenonquery()
$conn.close()

return $query
}

## Return ID from Database

function Return-Info($CliRef)
{
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result
}

## Collect the file names

$FiNms = Get-ChildItem H:pstest -Name

## Loop through each file name

foreach ($FiNm in $FiNms)
{

## Variable for current File path
$file = “H:pstest” + $FiNm

## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $CliRef
$ID = $ID + “.docx”
Copy-Item $file -Destination $newFile
Rename-Item $file $ID -force
}









share|improve this question
















bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • "I am not getting the results I need" - describe what you ARE getting and maybe someone will try to help you.

    – August
    Jan 21 '13 at 16:28
















0















I am trying to use a Powershell script to use the account number in a file name and re-name with the ID number from a sql database. Below is the code I am using to attempt this and I am not getting the results I need. Please let me now if you have any suggestion or advise in getting this to work.



Thanks!!



File name = 111119999.docx



Table =



ID AccountNumber



5555 111119999



## Select Data from Database

function Select-Info($CliRef)
{
$conn = new-object System.Data.SqlClient.SqlConnection
$connstring = “provider=sqloledb;data source=[vmsvr039];initial catalog=[crs5_oltp];integrated security=SSPI”
$conn.connectionstring = $connstring

$conn.open()
$query = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn)
$cmd.connection = $conn
$cmd.commandtext = $query
$result = $cmd.executenonquery()
$conn.close()

return $query
}

## Return ID from Database

function Return-Info($CliRef)
{
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result
}

## Collect the file names

$FiNms = Get-ChildItem H:pstest -Name

## Loop through each file name

foreach ($FiNm in $FiNms)
{

## Variable for current File path
$file = “H:pstest” + $FiNm

## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $CliRef
$ID = $ID + “.docx”
Copy-Item $file -Destination $newFile
Rename-Item $file $ID -force
}









share|improve this question
















bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • "I am not getting the results I need" - describe what you ARE getting and maybe someone will try to help you.

    – August
    Jan 21 '13 at 16:28














0












0








0








I am trying to use a Powershell script to use the account number in a file name and re-name with the ID number from a sql database. Below is the code I am using to attempt this and I am not getting the results I need. Please let me now if you have any suggestion or advise in getting this to work.



Thanks!!



File name = 111119999.docx



Table =



ID AccountNumber



5555 111119999



## Select Data from Database

function Select-Info($CliRef)
{
$conn = new-object System.Data.SqlClient.SqlConnection
$connstring = “provider=sqloledb;data source=[vmsvr039];initial catalog=[crs5_oltp];integrated security=SSPI”
$conn.connectionstring = $connstring

$conn.open()
$query = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn)
$cmd.connection = $conn
$cmd.commandtext = $query
$result = $cmd.executenonquery()
$conn.close()

return $query
}

## Return ID from Database

function Return-Info($CliRef)
{
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result
}

## Collect the file names

$FiNms = Get-ChildItem H:pstest -Name

## Loop through each file name

foreach ($FiNm in $FiNms)
{

## Variable for current File path
$file = “H:pstest” + $FiNm

## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $CliRef
$ID = $ID + “.docx”
Copy-Item $file -Destination $newFile
Rename-Item $file $ID -force
}









share|improve this question
















I am trying to use a Powershell script to use the account number in a file name and re-name with the ID number from a sql database. Below is the code I am using to attempt this and I am not getting the results I need. Please let me now if you have any suggestion or advise in getting this to work.



Thanks!!



File name = 111119999.docx



Table =



ID AccountNumber



5555 111119999



## Select Data from Database

function Select-Info($CliRef)
{
$conn = new-object System.Data.SqlClient.SqlConnection
$connstring = “provider=sqloledb;data source=[vmsvr039];initial catalog=[crs5_oltp];integrated security=SSPI”
$conn.connectionstring = $connstring

$conn.open()
$query = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn)
$cmd.connection = $conn
$cmd.commandtext = $query
$result = $cmd.executenonquery()
$conn.close()

return $query
}

## Return ID from Database

function Return-Info($CliRef)
{
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result
}

## Collect the file names

$FiNms = Get-ChildItem H:pstest -Name

## Loop through each file name

foreach ($FiNm in $FiNms)
{

## Variable for current File path
$file = “H:pstest” + $FiNm

## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $CliRef
$ID = $ID + “.docx”
Copy-Item $file -Destination $newFile
Rename-Item $file $ID -force
}






powershell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 21 '13 at 16:26









August

3,0641117




3,0641117










asked Jan 18 '13 at 17:02









timtim

1




1





bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 3 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • "I am not getting the results I need" - describe what you ARE getting and maybe someone will try to help you.

    – August
    Jan 21 '13 at 16:28



















  • "I am not getting the results I need" - describe what you ARE getting and maybe someone will try to help you.

    – August
    Jan 21 '13 at 16:28

















"I am not getting the results I need" - describe what you ARE getting and maybe someone will try to help you.

– August
Jan 21 '13 at 16:28





"I am not getting the results I need" - describe what you ARE getting and maybe someone will try to help you.

– August
Jan 21 '13 at 16:28










1 Answer
1






active

oldest

votes


















0














By changing the $ID = Return-Info $CliRef to $ID = Return-Info $FiNm I was able to get this to work. The file name will also need to have the ".docx" removed.



## Return ID from Database
function Return-Info($CliRef)
{

$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result

}

## Collect the image names
$FiNms = Get-ChildItem H:pstest -Name

## Loop through each Image name
foreach ($FiNm in $FiNms)

{

## Variable for current File path
$file = “H:pstest” + $FiNm
## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $FiNm

$ID = $ID + “.docx”

Copy-Item $file -Destination $newFile

Rename-Item $file $ID -force

}





share|improve this answer


























  • please use the Code Sample formatting in the future to make it easier to read when pasting a script or other code - this is the {} symbol in the menu above where you type a question/answer

    – August
    Jan 21 '13 at 17:01











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f470436%2flookup-file-name-in-sql-and-rename-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














By changing the $ID = Return-Info $CliRef to $ID = Return-Info $FiNm I was able to get this to work. The file name will also need to have the ".docx" removed.



## Return ID from Database
function Return-Info($CliRef)
{

$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result

}

## Collect the image names
$FiNms = Get-ChildItem H:pstest -Name

## Loop through each Image name
foreach ($FiNm in $FiNms)

{

## Variable for current File path
$file = “H:pstest” + $FiNm
## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $FiNm

$ID = $ID + “.docx”

Copy-Item $file -Destination $newFile

Rename-Item $file $ID -force

}





share|improve this answer


























  • please use the Code Sample formatting in the future to make it easier to read when pasting a script or other code - this is the {} symbol in the menu above where you type a question/answer

    – August
    Jan 21 '13 at 17:01
















0














By changing the $ID = Return-Info $CliRef to $ID = Return-Info $FiNm I was able to get this to work. The file name will also need to have the ".docx" removed.



## Return ID from Database
function Return-Info($CliRef)
{

$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result

}

## Collect the image names
$FiNms = Get-ChildItem H:pstest -Name

## Loop through each Image name
foreach ($FiNm in $FiNms)

{

## Variable for current File path
$file = “H:pstest” + $FiNm
## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $FiNm

$ID = $ID + “.docx”

Copy-Item $file -Destination $newFile

Rename-Item $file $ID -force

}





share|improve this answer


























  • please use the Code Sample formatting in the future to make it easier to read when pasting a script or other code - this is the {} symbol in the menu above where you type a question/answer

    – August
    Jan 21 '13 at 17:01














0












0








0







By changing the $ID = Return-Info $CliRef to $ID = Return-Info $FiNm I was able to get this to work. The file name will also need to have the ".docx" removed.



## Return ID from Database
function Return-Info($CliRef)
{

$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result

}

## Collect the image names
$FiNms = Get-ChildItem H:pstest -Name

## Loop through each Image name
foreach ($FiNm in $FiNms)

{

## Variable for current File path
$file = “H:pstest” + $FiNm
## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $FiNm

$ID = $ID + “.docx”

Copy-Item $file -Destination $newFile

Rename-Item $file $ID -force

}





share|improve this answer















By changing the $ID = Return-Info $CliRef to $ID = Return-Info $FiNm I was able to get this to work. The file name will also need to have the ".docx" removed.



## Return ID from Database
function Return-Info($CliRef)
{

$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=vmsvr039;Database=crs5_oltp;Integrated Security=SSPI;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.commandtext = “Select convert(varchar,cnsmr_accnt_idntfr_agncy_id) as ID FROM cnsmr_accnt WHERE cnsmr_accnt_crdtr_rfrnc_id_txt = '$CliRef'”
$cmd.connection = $conn
$result = $cmd.ExecuteScalar()
$conn.close()

return $result

}

## Collect the image names
$FiNms = Get-ChildItem H:pstest -Name

## Loop through each Image name
foreach ($FiNm in $FiNms)

{

## Variable for current File path
$file = “H:pstest” + $FiNm
## Variable for new File path
$newFile = “H:psrenamed” + $FiNm

$ID = Return-Info $FiNm

$ID = $ID + “.docx”

Copy-Item $file -Destination $newFile

Rename-Item $file $ID -force

}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 21 '13 at 17:01









August

3,0641117




3,0641117










answered Jan 21 '13 at 16:55









timtim

1




1













  • please use the Code Sample formatting in the future to make it easier to read when pasting a script or other code - this is the {} symbol in the menu above where you type a question/answer

    – August
    Jan 21 '13 at 17:01



















  • please use the Code Sample formatting in the future to make it easier to read when pasting a script or other code - this is the {} symbol in the menu above where you type a question/answer

    – August
    Jan 21 '13 at 17:01

















please use the Code Sample formatting in the future to make it easier to read when pasting a script or other code - this is the {} symbol in the menu above where you type a question/answer

– August
Jan 21 '13 at 17:01





please use the Code Sample formatting in the future to make it easier to read when pasting a script or other code - this is the {} symbol in the menu above where you type a question/answer

– August
Jan 21 '13 at 17:01


















draft saved

draft discarded




















































Thanks for contributing an answer to Server Fault!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f470436%2flookup-file-name-in-sql-and-rename-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

Список ссавців Італії Природоохоронні статуси | Список |...

Українські прізвища Зміст Історичні відомості |...