so i am working with a bit of code that after setting a static location for the CSV i am using for import. When i run the code it seems to run until i get the Windows can't open this File pop. you know the one with what do you want to do options, like user the web services to find the correct program. i am copying the code so hopefully someone can point on where i made this fubar. just for note before i made the CSV static the Script asked you to type the location in every time so maybe i missed a setting there

if ($args[0] -eq $null)
    { 
    $userNameFile = D:\lync_creation\userlog.csv
    $userNameFile  = $usernamefile -replace '"',""}  
else  
    {$usernamefile = $args[0]} 
if ($userNameFile -ne "")  
    {$csv=import-csv $userNameFile}  
else  
    {"Could not find a valid .csv with the user information." 
    exit} 
foreach($c in $csv) 
# enable for lync 
{ 
"Enabling " + $c.Identity + " for Lync 2010" 
Enable-csuser -identity $c.Identity -registrarpool pool01.west.com –sipaddresstype EmailAddress
}
write-host "Press any key to continue..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC") 
有帮助吗?

解决方案

You are seriously over complicating things if you're just going to use a static location for your CSV file.

$csv = Import-CSV D:\lync_creation\userlog.csv
foreach($c in $csv){ 
    "Enabling $($c.Identity) for Lync 2010" 
    Enable-csuser -identity $c.Identity -registrarpool pool01.west.com –sipaddresstype EmailAddress
}
write-host "Press any key to continue..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")

The first line imports the CSV file into a variable.

The next 4 loops through all entries in that variable, write the host who it's enabling and then enables the person.

The last 2 lines give a Press any key to continue message and then waits for a key press before continuing.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top